Some struct with flexible array:
struct SomeArray { unsigned length; int array[]; };
This code gcc (ver. 4.9.2) compiling with no errors:
struct s1{ unsigned length; SomeArray some_array; const char * string; } ss1;
How this work?
Some struct with flexible array:
struct SomeArray { unsigned length; int array[]; };
This code gcc (ver. 4.9.2) compiling with no errors:
struct s1{ unsigned length; SomeArray some_array; const char * string; } ss1;
How this work?
From the standard:
As a special case, the last element of a structure with more than one named member may have an incomplete array type; this is called a flexible array member. In most situations, the flexible array member is ignored. In particular, the size of the structure is as if the flexible array member were omitted except that it may have more trailing padding than the omission would imply.
This seems to be one of the situations where the flexible array member is ignored. So the size of ss1.some_array
doesn't include space for ss1.some_array.array
.