C/C++ Programmer's Guide (G06.27+, H06.08+, J06.03+)

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.
Unless you delete a macro definition, it remains in effect for the remainder of the translation
unit.
Avoid invoking macros with arguments that cause side effects. When the macro evaluates an
argument more than once, it also produces the side effect more than once, sometimes with
unexpected results. For example, if you invoke the sqr macro (defined in the second example)
with argument x++:
y = sqr(x++);
the preprocessor expands it to:
y = ((x++) * (x++));
This expansion causes the side effect (increment of x) to occur twice.
Examples
1. This example defines the object-like macro EOF to represent the constant -1:
#define EOF (-1)
2. This example defines the function-like macro sqr and then uses it in an assignment:
#define sqr(parm) ((parm) * (parm))
int main(void)
{
int a,b;
a = 12;
b = sqr(a);
}
After expanding the macro invocation and substituting the argument for the parameter in the
replacement list, the assignment to b looks like this:
b = ((a) * (a));
#error
The #error directive allows you to force a compilation error and terminate compilation.
154 Preprocessor Directives and Macros