C/C++ Programmer's Guide (G06.25+)
HP C/C++ Programmer’s Guide for NonStop Servers—429301-002
12-1
12
Preprocessor Directives and Macros
•
Directive #define on page 12-2
•
Directive #error on page 12-3
•
Directives #if, #elif, #ifdef, #ifndef, #else, and #endif on page 12-4
•
Directive #include on page 12-7
•
Directive #line on page 12-10
•
Directive #pragma on page 12-10
•
Directive #undef on page 12-10
•
Predefined Macros on page 12-11
•
Predefined Symbols on page 12-12
•
Variadic Macros on page 12-12
•
Feature-Test Macros on page 12-13
•
Preprocessor Operators on page 12-16
The preprocessor is a macro processor that processes the source text of a program
before the compiler parses the program.
The preprocessor is controlled by preprocessor directive lines that appear in your
source text. Preprocessor directive lines always begin with a number sign (#) in column
one. The name of the directive follows the number sign. The remainder of the line can
contain arguments for the directive.
Table 12-1 summarizes the preprocessor directives.
Table 12-1. Preprocessor Directives
#define
Defines a preprocessor macro and defines an identifier as the macro name.
#elif Conditionally includes text, depending on the value of a constant expression.
#else Conditionally includes text if the test on the related #if, #elif, #ifdef, or
#ifndef directive fails.
#endif Terminates conditional text.
#error Forces a compilation error and terminates compilation.
#if Conditionally includes text, depending on the value of a constant expression.
#ifdef Conditionally includes text, depending on whether an identifier is currently
defined as a macro name.
#ifndef Conditionally includes text, depending on whether an identifier is currently
undefined as a macro name.
#include Replaces the directive with the contents of a specified file.
#line Causes the compiler to renumber the lines in the source text.
#pragma Introduces a compiler pragma.
#undef Deletes a macro definition.