Versions Compared

Key

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

...

However, if required, members can be assigned explicit values, as in:

Code Block
bgColor#FFCCCC
enum {red=4, orange, yellow, green, blue, indigo=6, violet};

It may not be obvious to the programmer (though it is fully specified in the language) that yellow and indigo have been declared to be identical values (6), as are green and violet (7).

Compliant Solution

Enumeration type declarations must either

  • provide no explicit integer assignments, for example:
Code Block
bgColor#ccccff
enum {red, orange, yellow, green, blue, indigo, violet};
  • assign a value to the first member only (the rest are then sequential), for example:
Code Block
bgColor#ccccff
enum {red=4, orange, yellow, green, blue, indigo, violet};
  • assign a value to all members, so any equivalence is explicit, for example:
Code Block
bgColor#ccccff
enum {red=4, orange=5, yellow=1, green=5, blue=2, indigo=3, violet=7};

...

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

INT33 INT09-C A

1 (low)

1 (unlikely)

3 (low)

P3

L3

...