For portable applications, use only the assignment =
operator, the equality operators ==
and !=
, and the unary &
operator on plain character–typed or plain wide-character–typed expressions.
This is practice is recommended because the C standard Standard requires only the digit characters (0–9) to have consecutive numerical values. Consequently, operations that rely on expected values for plain character– or plain wide-character–typed expressions can lead to unexpected behavior.
...
This noncompliant code example attempts to determine if the value of a character variable is between 'a'
and 'c'
inclusive. However, because the C standard Standard does not require the letter characters to be in consecutive or in alphabetical or alphabetic order, the check might not work as expected.
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
STR09-C | low | unlikely | low | P3 | L3 |
Related Guidelines
...
Bibliography
[Jones 2009] | Section 5.2.1, "Character |
...
Sets" |
...