Reputation: 13608
In a current project, I'm experimenting around a lot to see the performance influence of different solutions. Since I like to keep all the code, I have a lot of #ifdef directives, which make it easy for me to switch on and off some optimizations. However, some combinations of defines are not covered. I'd like to see a compiler error if this happens, i.e.:
#define A
#define B
#ifdef A
#ifdef B
//invalid combination of defines. Compiler should raise an error.
#endif
#endif
#ifdef A
//do something
#endif
#ifdef B
//do something else
#endif
Is that possible?
Upvotes: 1
Views: 247
Reputation: 145919
#if defined(A) && defined(B)
#error invalid combination of defines
#endif
Upvotes: 2
Reputation: 183978
#ifdef A
#ifdef B
//invalid combination of defines. Compiler should raise an error.
#error Invalid combination
#endif
#endif
Upvotes: 2
Reputation: 523754
Yes. Just use the error directive (#error
).
#ifdef A
#ifdef B
#error "invalid combination of defines."
#endif
#endif
Upvotes: 7