### Conditional Compilation Directives

A preprocessor conditional compilation directive causes the preprocessor to conditionally suppress the compilation of portions of source code. These directives test a constant expression or an identifier to determine which tokens the preprocessor should pass on to the compiler and which tokens should be bypassed during preprocessing. The directives are:

- #if
- #ifdef
- #ifndef
- #else
- #elif
- #endif

For each #if, #ifdef, and #ifndef directive, there are zero or more #elif directives, zero or one #else directive, and one matching #endif directive. All the matching directives are considered to be at the same nesting level.

You can nest conditional compilation directives. In the following directives, the first #else is matched with the #if directive.

    #ifdef MACNAME
                   /*  tokens added if MACNAME is defined                */
    #   if TEST <=10
                   /* tokens added if MACNAME is defined and TEST <="10" */
    #   else
                   /* tokens added if MACNAME is defined and TEST>  10   */
    #   endif
    #else
                   /*  tokens added if MACNAME is not defined            */
    #endif

Each directive controls the block immediately following it. A block consists of all the tokens starting on the line following the directive and ending at the next conditional compilation directive at the same nesting level.

Each directive is processed in the order in which it is encountered. If an expression evaluates to zero, the block following the directive is ignored.

When a block following a preprocessor directive is to be ignored, the tokens are examined only to identify preprocessor directives within that block so that the conditional nesting level can be determined. All tokens other than the name of the directive are ignored.

Only the first block whose expression is nonzero is processed. The remaining blocks at that nesting level are ignored. If none of the blocks at that nesting level has been processed and there is a #else directive, the block following the #else directive is processed. If none of the blocks at that nesting level has been processed and there is no #else directive, the entire nesting level is ignored.

Preprocessor Directives
Preprocessing Operations
Preprocessor Macros

#elif Preprocessing Directive
#else Preprocessing Directive
#endif Preprocessing Directive
#if Preprocessing Directive
#ifdef Preprocessor Directive
#ifndef Preprocessor Directive
List of Preprocessing Directives