...
In the event that multiple statements in a macro is not bound in a do-while loop (see PRE10-C. Wrap multi-statement macros in a do-while loop), an if
statement with opening and closing braces will still ensure that all statements of the macro are properly executed.
...
This macro will expand correctly in a normal sequence of statements, but not as the then-clause in an if
statement:
Code Block | ||
---|---|---|
| ||
int x, y, z, tmp; if (z == 0) SWAP( x, y); |
...
Given an if
statement bounded with opening and closing braces, the macro would expand as intended.
Code Block | ||
---|---|---|
| ||
int x, y, z, tmp; |
...
if (z == 0) { |
...
tmp = x; |
...
x = y; |
...
y = tmp; |
...
} |