Information Technology Reference
In-Depth Information
Conditional Compilation
Conditional compilation allows you to mark a section of source code to be either compiled or
skipped, depending on whether a particular compilation symbol is defined.
There are four directives for specifying conditional compilation:
￿ #if
￿ #else
￿ #elif
￿ #endif
A condition is a simple expression that returns either true or false .
￿
A condition can consist of a single compilation symbol, or an expression of symbols
and operators, as summarized in Table 22-2. Sub-expressions can be grouped with
parentheses.
The literals true and false can also be used in conditional expressions.
￿
Table 22-2. Conditions Used in the #if and #elif Directives
True : If the symbol has been defined
using a #define directive.
False: Otherwise.
Compilation
symbol
Identifier, defined (or not) using the
#define directive.
True : If the expression evaluates to
true .
False: Otherwise.
Expression
Constructed using symbols and the
operators:
! , == , != , && , ||
The following are examples of conditional compilation conditions.
Expression
#if !DemoVersion
...
#endif Expression
#if (LeftHanded && OemVersion) || FullVersion
...
#endif
#if true // The following code segment will always be compiled.
...
#endif
Search WWH ::




Custom Search