Versions Compared

Key

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

...

This CUBE() macro definition is noncompliant because it fails to parenthesize the parameter names.

Code Block
bgColor#FFcccc
langc
#define CUBE(I) (I * I * I)

As a result, the invocation

Code Block
bgColor#FFcccc
langc
int a = 81 / CUBE(2 + 1);

expands to

Code Block
bgColor#FFcccc
langc
int a = 81 / (2 + 1 * 2 + 1 * 2 + 1);  /* evaluates to 11 */

...

Parenthesizing all parameter names in the CUBE() macro allows it to expand correctly (when invoked in this manner).

Code Block
bgColor#ccccFF
langc#ccccff
#define CUBE(I) ( (I) * (I) * (I) )
int a = 81 / CUBE(2 + 1);

...