Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!crdgw1!sungod!davidsen From: davidsen@sungod.crd.ge.com (William Davidsen) Newsgroups: comp.lang.c Subject: Re: Zero Length Arrays Allowed in C Standard? Message-ID: <4101@crdgw1.crd.ge.com> Date: 4 Dec 89 19:50:42 GMT References: <2298@jato.Jpl.Nasa.Gov> <11715@smoke.BRL.MIL> <480@codonics.COM> <1989Dec2.210042.12668@twwells.com> <8129@cg-atla.UUCP> Sender: news@crdgw1.crd.ge.com Reply-To: davidsen@crdos1.UUCP (bill davidsen) Organization: General Electric Corp. R&D, Schenectady, NY Lines: 21 In article <8129@cg-atla.UUCP> fredex@cg-atla.UUCP (Fred Smith) writes: | Excuse me, but I must ask a stupid question. Why the !@#$ would anyone even want | to declare an array of zero size ???? Isn't that rather similar to a pointer | to the same type of object?? If so, what is wrong with declaring a pointer | rather than an empty array ?? A pointer is not the same as an array (of any size). One use of an array of zero size (or one) is at the end of a struct definition. Then, if the actual struct is allocated by malloc et al, the size allocated can be larger than the size of the struct as defined, and the array will be addressable using positive non-zero subscripts. The array must be used instead of the pointer to insure that allignment considerations don't creep in. The portable solution is to declare the array with size one, and then adjust the size of the malloc call as needed. bill davidsen (davidsen@crdos1.crd.GE.COM) {uunet | philabs}!crdgw1!crdos1!davidsen "Stupidity, like virtue, is its own reward" -me