HP C/iX Reference Manual (31506-90011)

Chapter 7 107
Preprocessing Directives
Conditional Compilation
Conditional Compilation
Conditional compilation directives allow you to delimit portions of code that are compiled if
a condition is true.
Syntax
conditional-directive
:=
#if
constant-expression newline [group]
#ifdef
identifier newline [group]
#ifndef
identifier newline [group]
#else
newline [group]
#endif
Here,
constant-expression
may also contain the defined operator:
defined
identifier
defined (
identifier
)
Description
You can use #if, #ifdef, or #ifndef to mark the beginning of the block of code that will
only be compiled conditionally. An #else directive optionally sets aside an alternative
group of statements. You mark the end of the block using an #endif directive. The
structure of the conditional compilation directives can be shown using the #if directive:
#if
constant-expression
.
.
/* (Code that compiles if the expression evaluates */
/* to a nonzero value.) */
#else
.
.
/* (Code that compiles if the expression evaluates */
/* to a zero value.) */
#endif
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: