From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,27231e56b1afd21f X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1994-12-06 06:32:21 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!gatech!bloom-beacon.mit.edu!news.kei.com!travelers.mail.cornell.edu!newsstand.cit.cornell.edu!cheme.cornell.edu!OLIN From: olin@cheme.cornell.edu (Steve Thompson) Newsgroups: comp.unix.osf.osf1 Subject: Re: Funny alignment with structures ? Date: 6 Dec 1994 14:32:11 GMT Organization: Cornell University School of Chemical Engineering Sender: smt7@cornell.edu (Verified) Message-ID: <3c1slb$qb3@newsstand.cit.cornell.edu> References: Reply-To: olin@cheme.cornell.edu NNTP-Posting-Host: vger.cheme.cornell.edu In article , al012@svtstu.seqeb.gov.au (Anthony) writes: >In the following data structure: >U8 unsigned 8 bit >U16 unsigned 16 bit >U32 unsigned 32 bit > >typedef struct { > U8 major_version; /* Version - major */ > U8 minor_version; /* - minor */ > U16 flags; /* Control flags */ > U16 entry_size; /* Size of entries */ > U16 entry_count; /* Number of entries */ > U16 next_entry; /* Next entry number to be filled */ > U16 start_par; /* PAR of start of buffer data */ > U16 end_par; /* PAR past end of buffer data */ > U16 next_par; /* PAR of next entry rel to start of event file */ > U16 next_offset; /* Offset in PAR of next entry */ > U32 seqno; /* Entry sequence number */ > U16 updates; /* Entry update counter */ > U16 timeh; /* Time of last update */ > U16 timel; > U16 date; /* Date of last update */ > U8 spare[34]; /* Header is 64 bytes */ >} MUXEVB_HEADER; > >I thought the alignment would be like this: >[...] > >but I am getting this alignment >[...] > >Could someone please tell me how I can get around this funny alignment >arrangement ? Count the bytes: the U32 field has two U8 fields and eight U16 fields before it. Thats 2*1 + 8*2 = 18 bytes. Now since 18 is not a multiple of 4 (the size of a U32), you get padding. -steve /sig --------------------------------------------------------------------------- Steve Thompson, System Mangler Internet: thompson@cheme.cornell.edu School of Chemical Engineering Phone: (607) 255 5573 Olin Hall, Cornell University FAX: (607) 255 9166 Ithaca NY 14853 "Time is just one damn thing after another" ---------------------------------------------------------------------------