5 ms·
>I wondered if it just has constant expression semantics for const variables. That would be my guess also, for applicable const variables. File scope const var
by eMSF 7y ago
>I wondered if it just has constant expression semantics for const variables.
That would be my guess also, for applicable const variables. File scope const variables are quite constexpr-y in C anyway, since C requires all file scope variable initializers to be constant expressions (C++ only requires that for constexpr variables).
Toying around with clang in Godbolt, it seems that there are some quirks regarding this. The following is accepted:
static const int n = 0;
int buf[n]; // invalid zero-length array is accepted
// probably another non-standard extension
But the following is not, despite n having the same zero value:
static const int n;
int buf[n]; // complains about a file scope VLA