Versions Compared

Key

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

Enumeration types in C map to integers. The normal expectation is that each enumeration type member is distinct. However, there are some non-obvious nonobvious errors that are commonly made that cause multiple enumeration type members to have the same value.

...

In this noncompliant code example, enumeration type members can be are assigned explicit values:

...

Enumeration type declarations must eitherdo one of the following:

  • provide no explicit integer assignments, as in this example:

...

It is also advisable to provide a comment explaining why multiple enumeration type members are being assigned the same value so that future maintainers don't mistakenly identify this as an error.

Of these three options, the first "provide no explicit integer assignments" is the simplest, and consequently the preferred, approach in the typical case.

...