Struct C
{
BYTE c_val_1;
BYTE c_val_2;
}
Struct B
{
BYTE b_val_1;
BYTE b_len;
Struct b_val_2 C [0];
}
Struct A
{
BYTE a_len;
Struct B a_val_1 [0];
}
And have a longer structure exists in the two variables, how to deal with the
Struct D
{
BYTE d_len.
BYTE d_val_1 [0].
BYTE d_val_2 [0].
}
CodePudding user response:
You use this nested zero-length arrays, belong to "abuse of zero-length array" behavior; Because 0 length of the array is actually not allocate memory, just have the effect of A placeholder, such as struct a_val_1 understandable into strcut B * p_a_val_1;The compiler will not assign you a p_a_val_1 space, need application by means of dynamically allocated memory of malloc allocation, released immediately after use.
Here is to expose its an important faults: in structure, an array of 0 array must be in the final statement, has certain limitation, make use the
Back to the host's problem: use nested overlay, like the original poster is short of the desired result,
Remember: 0 length of the array is the use of flexible array point is behind the continuous memory space,
CodePudding user response:
Multiple nested structure, no problem,