Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ukma!xanth!kremer From: kremer@cs.odu.edu (Lloyd Kremer) Newsgroups: comp.lang.c Subject: Re: Structure padding Message-ID: <8449@xanth.cs.odu.edu> Date: 13 Apr 89 17:08:46 GMT References: <440@front.se> <8392@xanth.cs.odu.edu> <124@paix.ikp.liu.se> Organization: Old Dominion University, Norfolk, Va. Lines: 34 In article <124@paix.ikp.liu.se> pekka@paix.ikp.liu.se (Pekka Akselin [The Mad Midnight Hacker]) writes: >How about this??? > >union { > struct foo { > char Bar[3]; > char Baz[6]; > char Frotz[4]; > } fred; > char SomeString[3 + 6 + 4]; >} Strings; > >#define bar Strings.Bar >#define baz Strings.Baz >#define frotz Strings.Frotz > >Would there be padding between the Bar, Baz and Frotz arrays in this case? First, the constructs Strings.Bar etc. are not valid; it would be Strings.fred.Bar, and so on. As to internal padding: within the array, no; within the structure, maybe. So accessing Bar, Baz, and Frotz within Strings.SomeString may or may not be equivalent to accessing them as Strings.fred.{member_name}. The presence of the array within the union has no effect on the compiler's policy regarding internal padding within structures. Lloyd Kremer Brooks Financial Systems {uunet,sun....}!xanth!brooks!lloyd