1

The C11 standard specifies in section 6.7/5:

C11 6.7/5

A definition of an identifier is a declaration for that identifier that:

(...)

— for an enumeration constant, is the (only) declaration of the identifier;

(...)

Does the wording of the above paragraph state that

  1. A definition of an enumeration constant is a declaration that is the (only) declaration

  2. A definition of an enumeration constant is the (only) declaration?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • It means that you cannot declare an enumeration constant without also defining it. It also means you can't forward declare enumeration constants. However, scoping still applies so you could have: `enum { NAME1, NAME2 }; void function(void) { enum { NAME1 = 37, NAME2 = -57 }; … }`. – Jonathan Leffler Aug 29 '18 at 17:51

1 Answers1

1

It means that declaring an enumeration constant also defines it.

As a result, an enum constant cannot appear more than once in a scope within a translation unit. For example, the code below is invalid as it redeclares an enum constant:

enum a {
    AAA,
    BBB
};

enum b {
    BBB,   // error, redeclaration
    CCC
};
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
dbush
  • 205,898
  • 23
  • 218
  • 273