Studio:How does the STRIDE compiler handle zero-length arrays?
Under option, the STRIDE compiler allows an stucture member array to be declared with zero length. This is most frequently used for the last member of a structure (although it may be used for any member). The declaration of a zero length array affects the structure in the following ways:
1. The size of the structure will be adjusted upward, if necessary, so that it ends on a boundary suitable for a field of the declared array type.
2. The offset of the first member following the zero length array declaration, if one exists, will be adjusted upward to a boundary suitable for a field of the declared array type if necessary.
As an example, consider:
struct S {
char i;
int ary[0];
};
Assuming that char is one byte in size and requires single-byte alignment and int has four byte size and four byte alignment, then
sizeof(struct S) == 4.
If the zero length array had not been declared then
sizeof(struct S) == 1;