Reputation: 1671
globals.h
#define Id1 1
#define Id2 2
factory.h
Item* makeItem(int id);
Will including new ids in globals.h require recompile of files which use makeItem
with old Ids?
Also how to know which changes will require recompile or re-linking of dependents?
Upvotes: 0
Views: 29
Reputation: 1
you can just put all IDs in a char array and just define char pointer char* Id_array in globals.h,if you have new IDs included,just push it into the ID array and make Id_array points to ID array you construct.
Upvotes: -1
Reputation: 5233
Any change to globals.h will require recompile of files that #include globals.h or include header files that include globals.h. So if your list of IDs changes often, and lots of files depend on it, and your project is big, this might become a nuisance.
One way around it is to split globals.h into different h-files, so that each h-file is only used by a relatively small part of your project. Then, a change in one of them will not require too much recompiling.
If you do this, you typically face the challenge of keeping all of the IDs unique. If they are defined in different header files, then the developer making a change in one file may not know that she is causing a collision with an ID defined in another file. One solution to this is to follow a well documented convention, in which every h-file where IDs are defined has an associated range of IDs, and the ranges are not overlapping.
Upvotes: 2