struct foo { enum { MAXELEMENTS=10 }; long id[MAXELEMENTS]; };
enum hack, like this, acts in C (but not a good code style, see @Jonathan Leffler's comment). Because when id defined, MAXELEMENTS is qualified with an enumeration constant.
C99 6.2.1 Identifier areas
Elements of structure, union, and enumeration have an area that begins immediately after the appearance of the tag in the type specifier that declares the tag. Each enumeration constant has an area that begins immediately after the appearance of its defining enumerator in the list of enumerations. Any other identifier has a scope that begins immediately after the completion of its declaration.
And enumeration is a type of integer constant.
C99 6.6 Constant Expressions
An integer constant expression must be an integer type and must have only operands that are integer constants, enumeration constants, symbolic constants, sizeof expressions, the results of which are integer constants, and floating-point constants, which are direct operands of the cast. Cast operators in an integer constant expression must convert only arithmetic types to integer types, except that they are part of the operand for the sizeof operator.
Finally, an integer constant can be used in array declarations, see C99. 6.7.5.2. Manifest declaration. No wonder.
source share