HP C/iX Reference Manual (31506-90011)

108 Chapter7
Preprocessing Directives
Conditional Compilation
#ifdef max
#ifndef min
The #if preprocessing directive has the form:
#if
constant-expression
Use #if to test an expression. The compiler evaluates the expression in the directive. If it
is true (a nonzero value), the code following the directive is included. If the expression
evaluates to false (a zero value), the compiler ignores the code up to the next #else,
#endif, or #elif directive.
All macro identifiers that appear in the
constant-expression
are replaced by their
current replacement lists before the expression is evaluated. All defined expressions are
replaced with either 1 or 0 depending on their operands.
Whichever directive you use to begin the condition (#if, #ifdef, or #ifndef), you must
use #endif to end the if-section.
The following preprocessing directives are used to test for a definition:
#ifdef
identifier
#ifndef
identifier
They behave like the #if directive but are considered true if the
identifier
was
previously defined using a #define directive.
You can nest these constructions. Delimit portions of the source program using conditional
directives at the same level of nesting, or with a -D option on the command line.
Use the #else directive to specify an alternative section of code to be compiled if the #if,
#ifdef, or #ifndef conditions fail. The code after the #else directive is compiled if the
code following any of the if directives does not compile.
The #elif constant-expression directive tests whether a condition of the previous #if,
#ifdef,or#ifndef was false. #elif is syntactically the same as the #if directive and can
be used in place of an #else directive.
Examples
The following are examples of valid combinations of these conditional compilation
directives:
#ifdef SWITCH
/* compiled if SWITCH is defined */
#else
/* compiled if SWITCH is undefined */
#endif /* end of if */
#if defined(THING)
/* compiled if THING is defined */
#endif /* end of if */
#if A>47
/* compiled if A evaluates > 47 */
#else
#ifA<20