The #if and #elif directives compare the value of the expression to zero.
If the constant expression evaluates to a nonzero value, the tokens that immediately follow the condition are passed on to the compiler.
If the expression evaluates to zero and the conditional compilation directive contains a preprocessor #elif directive, the source text located between the #elif and the next #elif or #else preprocessor directive is selected by the preprocessor to be passed on to the compiler. The #elif directive cannot appear after the preprocessor #else directive.
All macros are expanded, any defined() expressions are processed and all remaining identifiers are replaced with the token 0.
The expressions that are tested must be integer constant expressions with the following properties:
defined identifier defined(identifier)
For example:
#if defined(TEST1) || defined(TEST2)
Note: If a macro is not defined, a value of 0 (zero) is assigned to it. In the following example, TEST must be a macro identifier:
#if TEST >= 1 printf("i = %d\n", i); printf("array[i] = %d\n", array[i]); #elif TEST <0 printf("array subscript out of bounds \n"); #endif
Conditional
Compilation Directives
Preprocessor
Directives
#else Preprocessor
Directive
#endif Preprocessor
Directive
#ifdef Preprocessor
Directive
#ifndef Preprocessor
Directive
List of Preprocessor
Directives