HP aC++/HP C A.06.20 Programmer's Guide
The macro name is then replaced by the list of tokens wherever it appears in the source
file (except inside of a string, 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 compilation unit.
The replacement-list must fit on one line. If the line becomes too long, it can be
broken up into several lines provided that all lines but the last are terminated by a
backslash (\) character. The following is an example:
#define mac very very long\
replacement string
The \ must be the last character on the line. You cannot add any spaces or comments
after it.
Macros can be redefined without an intervening #undef directive. Any parameter
used must agree in number and spelling with the original definition, and the
replacement lists must be identical. All white space within the replacement-list is treated
as a single blank space regardless of the number of white-space characters you use.
For example, the following #define directives are equivalent:
#define foo x + y
#define foo x + y
The replacement-list may be empty. If the token list is not provided, the macro
name is replaced with no characters.
Macros with Parameters
You can create macros that have parameters. The syntax of the #define directive that
includes formal parameters is as follows:
#define identifier( [identifier-list] ) [replacement-list]
The macro name is identifier. The formal parameters are provided by the
identifier-list enclosed in parentheses. The open parenthesis ( ‘(’ ) must
immediately follow the identifier with no intervening white space. If there is a space
between the identifier and the parenthesis, the macro is defined as if it were the first
form and 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 parenthesized list following the macro name. Commas 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.
156 Preprocessing Directives