Issue: definition of variable length array (VLA) / known constant size seems to be recursive.
C11, 6.2.5 Types, 23 (emphases added):
A type has known constant size if the type is not incomplete and is not a variable length array type.
C11, 6.7.6.2 Array declarators, 4 (emphases added):
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; otherwise, the array type is a variable length array type.
These quotes can be pseudo-coded as:
is_KCS(T) = !is_INCOMPL(T) && !is_VLA(T)
is_VLA(T) = !(is_ICE(S(T)) && is_KCS(ET(T)))
Here we see that:
is_VLAdepends onis_KCS, which depends onis_VLA(and so on)is_KCSdepends onis_VLA, which depends onis_KCS(and so on)
Questions:
- Is definition of variable length array (VLA) / known constant size indeed recursive?
- If yes, then is it a defect in the standard?
In C2X (n3299.pdf) the quotes above a bit changed, but the issue remains.
int arr[x][5]wherexis not a constant. Thenarris an array of constant size 5 whose elements are of the variable-length typeint[x].is_VLA(T) = is_array(T) && !(is_ICE(S(T)) && is_KCS(ET(T))). Whenis_VLAis "called" recursively, it's not with the same original typeT, but with its element typeET(T)which is necessarily different. The recursion could continue for a finite number of steps, but eventually eitheris_array()will return false oris_ICEwill return true, and then the recursion terminates.