...
Code Block | ||||
---|---|---|---|---|
| ||||
/* * Swaps two values. * Requires tmp variable to be defined. */ #define SWAP(x, y) \ tmp = x; \ x = y; \ y = tmp |
This macro will expand expands 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); |
It will expand expands to the following, which is certainly not what the programmer intended:
...