As others have said, it is valid. But I think no one has quoted the right sections so far. The relevant ones from the N1256 C99 draft are: 6.6 "Constant expressions" paragraph 6:
An integer constant expression99) shall have integer type and shall only have operands that are integer constants, enumeration constants [...]
and then 6.7.5.2 "Array declarators" paragraph 4:
If the size is an integer constant expression and the element type has a known constant size, the array type is not a variable length array type [...]
So basically:
- enumeration constants are constant expressions
- for the array not to be variable length, we need a constant expression
I believe that 6.7.2.2 "Enumeration specifiers" which others quoted talks about declaring the enum
, not using the enumerators. Of course, since when declaring them you need compile time constants, we expect that they should also be compile time constants when used in expressions.