Zero Length Arrays Allowed in C Standard?

Glenn Fowler[drew] gsf at ulysses.homer.nj.att.com
Fri Dec 8 00:06:42 AEST 1989


In article <70188 at psuecl.bitnet>, c9h at psuecl.bitnet writes:
> > <1989Dec5.112553.24087 at twwells.com> <11963 at phoenix.Princeton.EDU> <8141 at cg-atla.UUCP> <11759 at smoke.BRL.MIL>
> It seems that the main reason (and *only* even half-way decent reason) for
> using a 0-length array is to allocate a variable amount of memory for a
> structure depending on the length of the array.  This seems reasonable.

why not make the last element huge rather than small and then at malloc time
decrease the sizeof rather than increase:

	struct x
	{
		...
		char var[max_size];
	} *p;

	p = (struct x*)malloc(sizeof(struct x) - max_size + current_size);

or is this just as sleazy as the undersized array example?
-- 
Glenn Fowler    (201)-582-2195    AT&T Bell Laboratories, Murray Hill, NJ
uucp: {att,decvax,ucbvax}!ulysses!gsf       internet: gsf at ulysses.att.com



More information about the Comp.lang.c mailing list