Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: macro name EOF fixed to END_OF_FILE.

...

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

In this example, the programmer has mistakenly omitted the comparison operator from the conditional statement, which should be getchar() != END_OF_FILE. (See void MSC02-C. Avoid errors of omission.) After macro expansion, the conditional expression is incorrectly evaluated as a binary operation: getchar()-1. This statement is syntactically correct, even though it is certainly not what the programmer intended. Note that this example also violates DCL00-C. Const-qualify immutable objects.

...