cpp.info: Misnesting
Go forward to Macro Parentheses
Go backward to Macro Pitfalls
Go up to Macro Pitfalls
Go to the top op cpp
Improperly Nested Constructs
Recall that when a macro is called with arguments, the arguments are
substituted into the macro body and the result is checked, together with
the rest of the input file, for more macro calls.
It is possible to piece together a macro call coming partially from
the macro body and partially from the actual arguments. For example,
#define double(x) (2*(x))
#define call_with_1(x) x(1)
would expand `call_with_1 (double)' into `(2*(1))'.
Macro definitions do not have to have balanced parentheses. By
writing an unbalanced open parenthesis in a macro body, it is possible
to create a macro call that begins inside the macro body but ends
outside of it. For example,
#define strange(file) fprintf (file, "%s %d",
...
strange(stderr) p, 35)
This bizarre example expands to `fprintf (stderr, "%s %d", p, 35)'!
Created Wed Sep 1 16:42:06 2004 on bee with info_to_html version 0.9.6.