Checking that two headers are simultaneously enabled
I need to make a statement based on two related macro processors #define
declared in different header files ... The codebase is huge and it would be nice if I could find a place to put the statement where the two headers are already included to avoid unnecessary use of namespaces ...
Checking that the file can contain both explicitly and insufficiently, as one (or both) of them can be included in the top level of the nesting inclusion hierarchy.
I know it wouldn't be easy to write a script to test this, but if there is already a tool out there that does the job, so much the better.
Example:
file foo.h
#define FOO 0xf
file bar.h
#define BAR 0x1e
I need to put somewhere (no matter where) something like this:
#if (2*FOO) != BAR
#error "foo is not twice bar"
#endif
Yes, I know the example is stupid as they can be substituted, so they are produced from another, but let's say that the included ones can be generated from different places that are not under my control and I just need to check that they match in compile time ... And I don't want to just add one of them after the other, as it might contradict the previous code that I didn't write, so I would like to find a file where both are already present.
In short: how can I find a file that includes (directly or indirectly) two other files?
a source to share
If you are using Unix or Unix-like system, you can use the utility makedepend
.
http://en.wikipedia.org/wiki/Makedepend
If you are on Windows there is a Sourceforge project called makedep that might work.
a source to share
How about the # pragma once operator? After that, you can forget to worry about multiple header file definitions ...
a source to share