...
When declaring immutable symbolic values, such as ADULT_AGE
, it is best to declare them as a constant in accordance with DCL00-A. Declare immutable objects as constantsnamed constant values.
Code Block | ||
---|---|---|
| ||
enum { ADULT_AGE=18 }; /* ... */ if (age >= ADULT_AGE) { /* Take action */ } else { /* Take a different action */ } /* ... */ |
...
In this compliant solution the magic number is replaced with an enumeration constant (see DCL00-A. Declare immutable objects as constantsnamed constant values).
Code Block | ||
---|---|---|
| ||
enum { BUFFER_SIZE=256 }; char buffer[BUFFER_SIZE]; /* ... */ fgets(buffer, BUFFER_SIZE, stdin); |
...