...
Wiki Markup |
---|
This is recommended because the C99 standard requires only the digit characters ('0' - '9') to have consecutive numerical values \[[C99 N1401]\]. Thus, operations that rely on expected values for plain character or plain wide character-typed expressions can lead to unexpected behavior. |
However, due to because of the requirement for digit characters, other operators can be used for them according to the following restrictions:
...
Noncompliant Code Example
The following example appears to check 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 = 't'; if ((ch == 'a') || (ch == 'b') || (ch == 'c')) { /* ... */ } |
Exceptions
STR09-EX1: It is okay to assume consecutive Consecutive values for characters like a~z
can be assumed on platforms where ASCII or Unicode is used. This rule is for raising awareness of guideline is primarily concerned with platform portability, such as for example, if the code is migrated from ASCII systems to non-ASCII systems.
...