C/C++ Programmer's Guide (G06.25+)

Preprocessor Directives and Macros
HP C/C++ Programmer’s Guide for NonStop Servers429301-002
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.
Usage Guidelines
If you need more than one physical line to complete the definition of a macro, place
a backslash (\) at the end of all but the last line of the definition. The backslashes
cause these physical lines to be concatenated into a single logical line.
The #ifdef and #ifndef directives enable you to test whether an identifier is
currently defined as a macro name.
The #undef directive enables you to remove a macro definition so that the
identifier is no longer defined as a macro name.
#define { object-like-name } replacement-list newline
{ function-like-name }
object-like-name:
identifier
function-like-name:
identifier( [parameter-list] )