...
Code Block | ||||
---|---|---|---|---|
| ||||
int x, y, z, tmp;
if (z == 0)
SWAP( x, y);
|
It expands to the following, which is certainly not what the programmer intended:
...
Code Block | ||||
---|---|---|---|---|
| ||||
/*
* Swaps two values and requires
* tmp variable to be defined.
*/
#define SWAP(x, y) { tmp = x; x = y; y = tmp; }
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
if (x > y)
SWAP(x, y); /* Branch 1 */
else
do_something(); /* Branch 2 */
|
...
Related Guidelines
CERT C++ Coding Standard | VOID PRE10-CPP. Wrap multistatement macros in a do-while loop |
ISO/IEC TR 24772:2013 | Pre-processor Directives [NMP] |
...