Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!lll-winken!uunet!mcvax!kth!draken!liuida!prodix!isadora!paix!pekka From: pekka@paix.ikp.liu.se (Pekka Akselin [The Mad Midnight Hacker]) Newsgroups: comp.lang.c Subject: Re: Structure padding Message-ID: <124@paix.ikp.liu.se> Date: 11 Apr 89 09:52:16 GMT References: <440@front.se> <8392@xanth.cs.odu.edu> Organization: PA Mikroresurs, Linkoping, Sweden Lines: 50 In article <8392@xanth.cs.odu.edu> kremer@cs.odu.edu (Lloyd Kremer) writes: >In article <440@front.se> zap@front.se (Svante Lindahl) writes: >>Consider a struct consisting of a few character arrays, for example: >> >> stuct foo { >> char bar[3]; >> char baz[6]; >> char frotz[4]; >> } fred; >> >>I need to know if I can safely assume that there will not be any >>padding between the arrays. [...] >You would simply define one big array (a C array is guaranteed to be >contiguous), and do the internal indexing yourself. There should be no >performance degradation since the compiler would arrange for such indexing >anyway. Also, some well-chosen macros could make using the strings easier. [...] 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? My compiler generates the following line for the union above; .comm _Strings,13 and the same for structure fred; .comm _fred,13 Have a nice day! -- Pekka [The Mad Midnight Hacker Strikes Again] _______________________________________________________________________________ pekka@paix.ikp.liu.se ...!uunet!enea!liuida!prodix!paix!pekka Pekka Akselin, PA Mikroresurs, Sweden (The Land Of The Mad Midnight Hacker 8-)