...
Code Block | ||||
---|---|---|---|---|
| ||||
#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.
...