HP C/iX Reference Manual (31506-90011)

Chapter 7 103
Preprocessing Directives
Macro Replacement
Macro Replacement
You can define text substitutions in your source file with C macro definitions.
Syntax
macro-directive
:=
#define
identifier [replacement-list]
#define
identifier
(
[identifier-list]
)
[replacement-list]
#undef
identifier
replacement-list
:=
token
replacement-list token
Description
A #define preprocessing directive of the form:
#define
identifier [replacement-list]
defines the identifier as a macro name that represents the replacement list. The macro
name is then replaced by the list of tokens wherever it appears in the source file (except
inside of a string or character constant, or comment). A macro definition remains in force
until it is undefined through the use of the #undef directive or until the end of the
translation unit.
Macros can be redefined without an intervening #undef directive. Any parameters used
must agree in number and spelling, and the replacement lists must be identical. All
whitespace is treated equally.
The replacement-list may be empty. If the token list is not provided, the macro name is
replaced with no characters.
If the define takes the form
#define
identifier
(
[identifier-list]
)
replacement-list
a macro with formal parameters is defined. The macro name is the identifier and the
formal parameters are provided by the identifier-list which is enclosed in parentheses. The
first parenthesis must immediately follow the identifier with no intervening whitespace. If
there is a space between the identifier and the (, the macro is defined as if it were the first
form and that the replacement list begins with the ( character.
The formal parameters to the macro are separated with commas. They may or may not
appear in the replacement list. When the macro is invoked, the actual arguments are
placed in a parentheses-enclosed list following the macro name. Comma tokens enclosed in
additional matching pairs of parentheses do not separate arguments but are themselves
components of arguments.
The actual arguments replace the formal parameters in the token string when the macro is
invoked.