Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!decwrl!sun-barr!newstop!male!matilda!harry From: harry@matilda.uk.sun.com (Harry Protoolis - Sun EHQ) Newsgroups: comp.lang.c Subject: Re: Variable structure size -- ANSI ? Message-ID: <6246@male.EBay.Sun.COM> Date: 12 Apr 91 19:29:55 GMT References: <8334@umd5.umd.edu> <3111@kluge.fiu.edu> <4204@rwthinf.UUCP> Sender: news@male.EBay.Sun.COM Reply-To: harry.protoolis@uk.1.com Organization: Sun Microsystems Europe Inc Lines: 31 |> 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. Like, my smart compiler couldn't decide to 'shuffle' them around for reasons best known to itself could it ?, ... or could it ? IMHO the technique used above is inferior to using char *filename and mallocing the space separately simply for reasons of clarity, and if a compiler might shuffle structure elements around it could one day lead to some rather curious bugs ... Harry --- (smart Internet mailers) harry.protoolis@uk.sun.com (smart JANET mailers) harry.protoolis@sun-microsystems.co.uk (dumb uucp mailers) ...!sun!sunuk!harry.protoolis 'When I give food to the poor they call me a saint. When I ask why the poor have no food they call me a communist.' - Dom Helder Camara