Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!ulysses!gsf From: gsf@ulysses.homer.nj.att.com (Glenn Fowler[drew]) Newsgroups: comp.lang.c Subject: Re: Zero Length Arrays Allowed in C Standard? Summary: expand vs. shrink Message-ID: <12468@ulysses.homer.nj.att.com> Date: 7 Dec 89 13:06:42 GMT References: <2298@jato.Jpl.Nasa.Gov> <11715@smoke.BRL.MIL> <480@codonics.COM> <70188@psuecl.bitnet> Organization: AT&T Bell Laboratories, Murray Hill Lines: 21 In article <70188@psuecl.bitnet>, c9h@psuecl.bitnet writes: > > <1989Dec5.112553.24087@twwells.com> <11963@phoenix.Princeton.EDU> <8141@cg-atla.UUCP> <11759@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@ulysses.att.com