HP C A.06.05 Reference Manual

Preprocessing Directives
Conditional Compilation (#if, #ifdef, ..#endif)
Chapter 7 197
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
Valid combinations of these conditional compilation directives follow:
#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
#if A < 20
/* compiled if A evaluates < 20 */
#else
/* compiled if A >= 20 and <= 47 */
#endif /* end of if, A < 20 */
#endif /* end of if, A > 47 */
Examples
#ifdef (HP9000_S800) /* If HP9000_S800 is defined, INT_SIZE */
#define INT_SIZE 32 /* is defined to be 32 (bits). */
#elif defined (HPVECTRA) && defined (SMALL_MODEL)
#define INT_SIZE 16 /* Otherwise, if HPVECTRA and */
#endif /* SMALL_MODEL are defined,INT_SIZE is */
#ifdef DEBUG /* If DEBUG is defined, display the */
printf("table element : \n"); /* table elements. */
for (i=0; i < MAX_TABLE_SIZE; ++i)
printf("%d %f\n", i, table[i]);
#endif