Martin Sebor <mse...@gmail.com> writes: > @@ -1553,12 +1553,28 @@ struct line *thisline = (struct line *) > thisline->length = this_length; > @end smallexample > > -In ISO C90, you would have to give @code{contents} a length of 1, which > -means either you waste space or complicate the argument to @code{malloc}. > +Although the size of a zero-length array is zero, an array member of > +this kind may increase the size the enclosing type as a result of tail > +padding. The offset of a zero-length array member from the beginning > +of the enclosing structure is the same as the offset of an array with > +one or more elements of the same type. The alignment of a zero-length > +array is the same as the alignment of its elements. > > -In ISO C99, you would use a @dfn{flexible array member}, which is > -slightly different in syntax and semantics: > +Declaring zero-length arrays in other contexts, including as interior > +members of structure objects or as non-member objects is discouraged. > +Accessing elements of zero-length arrays declared in such contexts is > +undefined and may be diagnosed. > > +In the absence of the zero-length array extension, in ISO C90 the > +@code{contents} array in the example above would typically be declared > +to have a single element. Although this technique is discouraged, GCC > +handles trailing one-element array members similarly to zero-length > +arrays.
This last sentence seems a bit vague. E.g. GCC should never diagnose an access to element 0 of a 1-element trailing array, whereas (like you say above) it might for zero-length trailing arrays. Thanks, Richard