Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
langc
/*
 * 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
bgColor#FFcccc
langc
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:

...