Arrays declared as static
or at file scope (i.e. having static storage duration) cannot be variable length arrays:
From section 6.7.6.2 of the C standard:
If an identifier is declared as having a variably modified
type, it shall be an ordinary identifier (as defined in
6.2.3), have no linkage, and have either block scope or function prototype scope. If an identifier is declared to be
an object with static or thread storage duration, it shall not
have a variable length array type.
Even though the length is specified by a const int
, it is not considered a constant expression. Even using a size of type static const int
doesn't satisfy this requirement.
Note that this is different in C++, where a static const int
is considered a constant expression. C++11 also defines the constexpr
keyword for this purpose.