You do not have arrays of structures with flexible array elements.
Standard C, ISO / IEC 9899: 2011, says:
6.7.2.1 Structure and Association Specifications
ΒΆ3 A structure or union should not contain an element with an incomplete or functional type (therefore, the structure should not contain an instance of itself, but may contain a pointer to the instance by itself), except that the last member of the structure with more than one named member may have an incomplete array type; such a structure (and any union containing, possibly recursively, an element that is such a structure) should not be a member of the structure or an array element.
Accent is added - the italic part of this prohibits arrays of structures with flexible array elements. However, you may have arrays of pointers to such structures, but each structure will be allocated separately.
ΒΆ18 As a special case, the last structure element with more than one named element may have an incomplete array type; this is called a flexible array element. In most situations, the flexible array element is ignored. In particular, the size of the structure looks as if the flexible element of the array were excluded, except that it may have a longer addition than an omission would mean. However, when the operator .
(or ->
) has a left operand that has a (pointer to) structure with a flexible member of an array and names of right operands that are a member, it behaves as if this element were replaced by the longest array (with the same element type), which will not make the structure larger than the object being accessed; the offset of the array must remain equal to the element of the flexible array, even if it differs from the replacement matrix. If this array does not contain any elements, it will behave as if it had one element, but the behavior is undefined if attempts are made to access this element or create a pointer that passes by it.
This defines the flexible element of the array.
If you think about it, that makes sense. Arithmetic of pointers and arrays rely on all objects in the array having the same size (hence the equivalence of a[i] == *(a + i)
, etc.), therefore, the presence of an array of objects of different sizes will break the pointer arithmetic. An array of pointers is not a problem because pointers are the same size, even if the specified objects have different sizes.
If you manage to force the compiler to ignore the violated constraint, then each element of the array will have a flexible array element with zero length, because the structures will be treated as having the size of the structure without a member of the array (which is the rule at work in most situations, the flexible array element is ignored). But the compiler must reject an array of structure type with a flexible array element; such a code violates the restriction (ΒΆ3 is in the restrictions section; ΒΆ18 is in the semantics section).