[WARNING]
Whenever the preprocessor evaluates a condition and finds a identifier which was not defined before, he implicitly takes its value to be the integral value 0. This C style behavior may arise in hard to find bug. So when the header file, which actually defines the value is not included or when the macro name was entered incorrectly, for example with a different case, then the preprocessor "#if" and "#elif" instructions wont behave as expected. Note: The pragma MESSAGE does not apply to this message because it is issued in the preprocessing phase.
#define _Debug_Me 1
...
void main(int i) {
#if Debug_Me // missing _ in front of _Debug_Me.
assert(i!=0);
#endif
}
The assert will never be reached.
This warning is a good candidate to be mapped to an error. To save test macros defined in some header files, also test if the macros are defined:
#define _Debug_Me
...
void main(int i) {
#ifndef(Debug_Me)
#error // macro must be defined above
#endif
#if Debug_Me // missing _ in front of _Debug_Me.
assert(i!=0);
#endif
}
The checking of macros with "#ifdef" and "#ifndef" cannot detect if the header file, a macro should define is really included or not. Note that using a undefined macro in C source will treat the macro as C identifier and so usually be remarked by the compiler. Also note a undefined macro has the value 0 inside of preprocessor conditions, while a defined macro with nothing as second argument of a "#define" replaces to nothing. E.g.
#define DEFINED_MACRO
#if UNDEFINED_MACRO // evaluates to 0, giving this warning
#endif
if DEFINED_MACRO // error FATAL: C4435: Illegal
// expression in conditional expression
#endif