Studio:How does the STRIDE compiler handle zero-length arrays?

From STRIDE Wiki
Revision as of 22:40, 31 January 2008 by Robg (talk | contribs)
Jump to navigation Jump to search

Under option, the STRIDE compiler allows a stucture member 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 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;