Directive #ifdef Foundation
Compiles code when a symbol is defined
#ifdef <Symbol>
<SourceCode>...
[ #else
<SourceCode>...
]
#endif
The directives #ifdef...#else...#endif form a control structure for the preprocessor. When the preprocessor constant <Symbol> has been defined previous to the preprocessor encountering the #ifdefdirective, the preprocessor translates and outputs the source code located between the directives #ifdef and #else to the intermediary file. If no #else directive is present, the preprocessor translates and outputs the source code located between the directives #ifdef and #endif.
#ifdef provides support for conditional compilation. The preprocessor translates the source code subsequent to the directive #ifdef only when the preprocessor constant <Symbol> has been previously defined. If this constant has not been defined the preprocessor translates the source code which is between the #elseand #endif directives. Whichever block of code the preprocessor ignores does not get translated and output to the intermediary file, and thus does not get compiled.
Conditional compilation is performed primarily during application development. Generally, the directives #ifdef and #endif are used to frame blocks of code that perform special error assertions. The #ifdef directives typically test for a #define constant indicating that DEBUG operations are ongoing. When debugging is completed, the special assertions are not required, and simply removing a single#define DEBUG statement in a master Include file and performing an application-wide recompile is all that is necessary to remove all assertion code.
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.