The C Preprocessor - Macro Pitfalls

Node: Macro Pitfalls Prev: Redefining Up: Macros

Pitfalls and Subtleties of Macros

In this section we describe some special rules that apply to macros and macro expansion, and point out certain cases in which the rules have counterintuitive consequences that you must watch out for.

Misnesting Macros can contain unmatched parentheses.
Macro Parentheses Why apparently superfluous parentheses
may be necessary to avoid incorrect grouping.
Swallow Semicolon Macros that look like functions
but expand into compound statements.
Side Effects Unsafe macros that cause trouble when
arguments contain side effects.
Self-Reference Macros whose definitions use the macros' own names.
Argument Prescan Actual arguments are checked for macro calls
before they are substituted.
Cascaded Macros Macros whose definitions use other macros.
Newlines in Args Sometimes line numbers get confused.


Up: Macros