Versions Compared

Key

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

...

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
bgColor#ccccff
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
bgColor#ccccff
enum { BUFFER_SIZE=256 };

char buffer[BUFFER_SIZE];
/* ... */
fgets(buffer, BUFFER_SIZE, stdin);

...