...
This noncompliant code example attempts to determine if the value of a character variable is between 'a'
and 'c'
inclusive. However, since the C99 standard does not require the letter characters to be consecutive or in alphabetical order, the check might not work as expected.
Code Block | ||||
---|---|---|---|---|
| ||||
char ch = 'b'; if ((ch >= 'a') && (ch <= 'c')) { /* ... */ } |
...
In this example, the specific check is enforced using compliant operations on character expressions.
Code Block | ||||
---|---|---|---|---|
| ||||
char ch = 't'; if ((ch == 'a') || (ch == 'b') || (ch == 'c')) { /* ... */ } |
...