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 replacement list.:

Excerpt
hiddentrue

compliant=no,enclose=yes,compile=yes

...

In this noncompliant code example, END_OF_FILE is defined as -1. The macro replacement list consists of a unary negation operator, followed by an integer literal 1.:

Code Block
bgColor#FFcccc
langc
#define END_OF_FILE -1
/* ... */
if (getchar() EOF) {
   /* ... */
}

...

Parenthesizing the -1 in the declaration of END_OF_FILE ensures that the macro expansion is evaluated correctly.:

Code Block
#define END_OF_FILE (-1)

...

Code Block
bgColor#ccccff
langc
enum { END_OF_FILE = -1 };
/* ... */
if (getchar() != END_OF_FILE) {
   /* ... */
}

Exceptions

PRE02-EX1: A macro that expands to a single identifier or function call is not affected by the precedence of any operators in the surrounding expression, so its replacement list need not be parenthesized.

Code Block
#define MY_PID getpid()

PRE02-EX2: A macro that expands to an array reference using the array-subscript operator [], or an expression designating a member of a structure or union object using either the member-access . or -> operators.

...