...
The meaning of the numeric literal 18 is not clear in this example.
| Code Block | ||
|---|---|---|
| ||
/* ... */ 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 | ||
|---|---|---|
| ||
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.
...