Versions Compared

Key

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

...

The meaning of the numeric literal 18 is not clear in this example.

Code Block
bgColor#ffcccc
/* ... */
if (age >= 18) {
   /* Take action */
}
...
if (age < 18) else {
  /* Take a different action */
}
/* ... */

Compliant Solution

The compliant solution replaces 18 with the symbolic constant ADULT_AGE to clarify the meaning of the code.

...

Code Block
bgColor#ccccff
enum { ADULT_AGE=18 };
/* ... */
if (age >= ADULT_AGE) {
   /* Take action */
}
...
if (age < ADULT_AGE) else {
  /* Take a different action */
}
/* ... */

Risk Assessment

Using numeric literals makes code more difficult to read and understand.

...