HP C A.06.05 Reference Manual

Preprocessing Directives
Conditional Compilation (#if, #ifdef, ..#endif)
Chapter 7196
The constant-expression is like other C integral constant expressions except that all
arithmetic is carried out in long int precision. Also, the expressions cannot use the sizeof
operator, a cast, or an enumeration constant.
You can use the defined operator in the #if directive to use expressions that evaluate to 0 or
1 within a preprocessor line. This saves you from using nested preprocessing directives.
The parentheses around the identifier are optional. For example:
#if defined (MAX) && ! defined (MIN)
.
.
.
Without using the defined operator, you would have to include the following two directives to
perform the above example:
#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 #ifdef is considered true if the
identifier
was
previously defined using a #define directive or the -D option. #ifndef is considered true if
the identifier is not yet defined.
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.