Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
bgColor#FFCCCC
langc
char ch = 'b';
if ((ch >= 'a') && (ch <= 'c')) {
  /* ... */
}

...

In this example, the specific check is enforced using compliant operations on character expressions.

Code Block
bgColor#CCCCFF
langc
char ch = 't';
if ((ch == 'a') || (ch == 'b') || (ch == 'c')) {
  /* ... */
}

...