The #if and #elif directives compare the value of constant_expression to zero:
#if and #elif directive syntax .----------------. V | >>-#--+-if---+--constant_expression----token_sequence-+-------->< '-elif-'
All macros are expanded, except macros that
are the operand of a defined operator. Any uses of the defined operator
are processed, and all remaining keywords and identifiers are replaced
with the token 0
except true and false.
The behavior is undefined if expanding the macros resulted in the token defined.
#if static_cast<int>(1)
#error Unexpected
#endif
int main() {
}
In C++0x, arithmetic
is performed using long long int type. See C99 preprocessor features adopted in C++0x (C++0x) for detailed information.defined identifier defined(identifier)
#if defined(TEST1) || defined(TEST2)
#include <stdio.h>
int main()
{
#if TEST != 0 // No error even when TEST is not defined.
printf("Macro TEST is defined to a non-zero value.");
#endif
}