Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!rochester!kodak!ispd-newsserver!ism.isc.com!bud.sos.ivy.isc.com!willcr From: willcr@bud.sos.ivy.isc.com (Will Crowder) Newsgroups: comp.lang.c Subject: Re: Variable structure size -- ANSI ? Message-ID: <1991Apr12.234258.23800@ism.isc.com> Date: 12 Apr 91 23:42:58 GMT References: <8334@umd5.umd.edu> <3111@kluge.fiu.edu> <4204@rwthinf.UUCP> <6246@male.EBay.Sun.COM> Sender: usenet@ism.isc.com (Ism Usenet News) Reply-To: willcr@ivy.isc.com Followup-To: comp.lang.c Organization: Interactive Systems Corp. Lines: 41 In article <6246@male.EBay.Sun.COM>, harry@matilda.uk.sun.com (Harry Protoolis - Sun EHQ) writes: > |> Michael N Johnston writes: > |> ]>struct foo { > |> ]>unsigned short recsize; > |> ]>unsigned short num; > |> ]>char info [24]; > |> ]>byte flags; > |> ]>char filename[1] > |> ]>}; > |> ]>Where, foo.filename is a placeholder for a variable length string. > |> > > A question really, does the standard *guarantee* the physical order of > structure elements ? I looked in K&R 2 and couldn't find anything. The ANSI standard guarantees that elements of a structure will be allocated in the order declared. However, there may be any amount of padding between structure elements. But yes, for struct foo { int a; int b; }; &foo.b is guaranteed to be greater then &foo.a. Also, &foo is guaranteed to be equal to &foo.a. |> Harry |> --- Hope this helps, Will -------------------------------------------------------------------------------- Will Crowder, MTS | "An optimist sees a glass that's half full. A (willcr@ivy.isc.com) | pessimist sees a glass that's half empty. An INTERACTIVE Systems Corp. | engineer sees a glass that's twice as big as | it needs to be!" -- unknown (at least, by me)