Zero Length Arrays Allowed in C Standard?

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Dec 7 08:10:32 AEST 1989


In article <2678 at cbnewsj.ATT.COM> asd at cbnewsj.ATT.COM (adam.denton,mt,) writes:
>What fathomable purpose could a programmer possibly want by
>declaring a zero-length array?  To store nothing?

What fathomable purpose could a programmer possibly want by
coding a loop that gets executed zero times?  To do nothing?

Possible uses for zero-sized objects (notably arrays) have
already been posted.  Let me add that there are no logical
problems with the concept; all properties of such objects
would be well defined.
	sizeof zero would be 0
	&zero points at the object
	++ptr_to_zero would still point to zero
	*ptr_to_zero needn't do anything to "access" the contents
	&zero_length_array[0] points one past the last valid element
etc.

As I recall, zero was invented by Arabic mathematicians
thousands of years ago.  It's a pity it still frightens
or confuses people.



More information about the Comp.lang.c mailing list