...
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 values using enum or constobjects as constants.
| 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 values using enum or constobjects as constants).
| Code Block | ||
|---|---|---|
| ||
enum { BUFFER_SIZE=256 };
char buffer[BUFFER_SIZE];
/* ... */
fgets(buffer, BUFFER_SIZE, stdin);
|
...