I have the following files: a.h
, a.c
, b1.c
, b2.c
and in both b1 and b2 I have some macro definitions which are identical.
Is it ok if I move them in a.h
or is it more common to leave them in the file where they are being used ? Which way is the proper way to do it in C ?
It is common to move macro definitions which are shared between files into a header which both of those files include. You should make sure that the file you move that definition into is a sensible file for it to be in; don't move it into a completely unrelated header just because it's included in both files. If there is no logical related header file for both b1.c
and b2.c
, perhaps you ought to create a b.h
to be shared between them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With