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-2
#define
#define
The #define directive defines a macro, providing it with a name (an identifier) and the
replacement list that the name represents. The macro can be either object-like or
function-like, depending on how you define it.
object-like-name
specifies the name of an object-like macro; it must be a valid identifier.
function-like-name
specifies the name and parameters (if any) of a function-like macro. The parameter
list is a parenthesized, comma-separated list of zero or more identifiers. Note that
there can be no white space between the macro identifier and the opening
parenthesis of the parameter list.
replacement-list
is the text that the preprocessor substitutes for the macro name when you invoke
the macro later in the translation unit. The replacement-list must be valid in
the context where you invoke it, not where you define it.
If the macro is function-like and has defined parameters, the preprocessor
substitutes each instance of a parameter identifier in the replacement-list with
its corresponding argument specified in the macro invocation. The second example
illustrates parameter substitution.
newline
is the newline character that terminates the directive line.
#line Causes the compiler to renumber the lines in the source text.
#pragma Introduces a compiler pragma.
#undef Deletes a macro definition.
#define { object-like-name } replacement-list newline
{ function-like-name }
object-like-name:
identifier
function-like-name:
identifier( [parameter-list] )
Table 12-1. Preprocessor Directives (page 2 of 2)