C/C++ Programmer's Guide (G06.27+, H06.03+)

Table Of Contents
Preprocessor Directives and Macros
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
12-7
#include
#if XCOORD == 10
printf("Intersection at (10,5).\n");
#elif YCOORD == 10
printf("Intersection at (5,10).\n");
#else
printf("Intersection at (5,5) \n");
#endif
3. This example shows how the #ifdef directive works. Because PC is defined as a
macro, the compiler processes the source text following the #ifdef PC directive.
The compiler ignores the source text following the #ifdef TNS directive because
TNS is undefined:
#define PC 1
#ifdef TNS
/* HP Tandem dependent code. */
printf("This program executes on the server.\n");
#endif
#ifdef PC
/* pc dependent code. */
printf("This program executes on the pc.\n");
#endif
4. This example shows how the #ifndef directive works. Because TNS is not
defined as a macro, the compiler processes the source text following the #ifndef
TNS directive. The compiler ignores the source text following the #ifndef PC
directive because PC is defined:
#define PC 1
#ifndef TNS
printf("TNS is not currently defined.\n");
#endif
#ifndef PC
printf("PC is not currently defined.\n");
#endif
#include
The #include directive includes source text from a specified file.
#include source_specifier [ nolist ] newline
source-specifier:
{ " source_file [ section_list ] " } |
{ < library_header_file [ section_list ] > }
section_list:
( section_name [ , section_name ]... )