Information Technology Reference
In-Depth Information
The Conditional Compilation Constructs
The #if and #endif directives are the matching demarcations of a conditional compilation
construct. Whenever there is an #if directive, there must also be a matching #endif .
The #if and #if...#else constructs are illustrated in Figure 22-1.
If the condition in the #if construct evaluates to true , the code section following it is
compiled. Otherwise, it is skipped.
￿
￿In the #if...#else construct, if the condition evaluates to true , CodeSection1 is com-
piled. Otherwise, CodeSection2 is compiled.
Figure 22-1. The #if and #else constructs
For example, the following code illustrates a simple #if...#else construct. If the symbol
RightHanded is defined, the code between the #if and the #else will be compiled. Otherwise,
the code between the #else and the #endif will be compiled.
...
#if RightHanded
// Code implementing right-handed functionality
...
#else
// Code implementing left-handed functionality
...
#endif
Search WWH ::




Custom Search