Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

proper C refactoring

Tags:

c

refactoring

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 ?

like image 552
hyperboreean Avatar asked Dec 16 '22 21:12

hyperboreean


1 Answers

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.

like image 138
Brian Campbell Avatar answered Dec 26 '22 20:12

Brian Campbell