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

Preprocessor Directives and Macros
HP C/C++ Programmer’s Guide for NonStop Servers429301-002
12-3
#error
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++ as follows:
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.
preprocessor-tokens
specifies the tokens to be included in the message text.
#error preprocessor-tokens