Unlike array declarations in function parameters, an array declared as part of a struct or union must have the specified size (with one exception, described below). That's why the announcement
int lost_index[]; int lost_index_size;
wrong.
An exception to this rule is the so-called “flexible array element”, which is an array declared without size at the end of the struct . You must put it at the end of the struct so that memory can be allocated for it along with the struct itself. This is the only way the compiler could know the offsets of all data members.
If the compiler needs to allow flexible arrays in the middle of the struct , the location of members starting with size , allowed_memory_key_size and on will depend on the amount of memory that you allocate lost_index[] . Moreover, the compiler will not be able to insert a struct where necessary to ensure proper access to memory.
source share