Zero Length Arrays Allowed in C Standard?

Peter Curran peter at isgtec.UUCP
Thu Dec 14 05:09:48 AEST 1989


This is a re-posting, due to technical difficulties.

WIthout repeating all the discussion, much of this topic has been centred
around a single zero-length array in a structure, for which the actual
size is to be determined when an instance is malloc'd.

The Rationale document (my copy is X3J11/88-091, 13 May 1988), in section
3.5.4.2, pp. 54-55, suggests the use of array size "1".  This works
just as well as zero, except you have to subtract 1 (or sizeof(elt[0]))
from the amount malloc'd (except for the most common use, a variable-length
string, where the initial element accounts for the terminating NUL).

I realize the Rationale is not part of the standard, but I think it
would take an awfully brave implementor to disallow a construct
that the Rationale condones.



More information about the Comp.lang.c mailing list