Firstly, I recognize that this may not be possible, as macros are only expanded once. However, I'm hoping there is some standard way of getting similar behavior, or suggestions for other methods to pursue.
I'm looking for a way to do a compile-time check on our build that would raise an error in the event of incompatibility. The following will, of course, not work, but is the easiest way in my mind to get the idea across:
version.h:
#define CODE_VERSION 2
#define VERSION(x) #if (CODE_VERSION > (x) ) \
#error "Incompatible version detected!" \
#endif
main.c:
#include "version.h"
VERSION(1)
// ...and so on
If the output from the preprocessor was fed back into the preprocessor, this ought to cause an error to appear during compilation.
So, what is the proper way to achieve this (or similar) behavior? For the curious, the thought behind of this is to avoid manual analysis during reviews of a reasonably large codebase to comply with an audit process (as automatic auditing is so much less burdensome).