From: "Michael Stewart" Newsgroups: comp.os.msdos.djgpp Subject: Re: annoying structure problem Date: Thu, 8 Jul 1999 11:31:52 +0100 Organization: (Posted via) Netcom Internet Ltd. Lines: 22 Message-ID: <7m1ul7$65r$1@taliesin.netcom.net.uk> References: <7m1u1e$pnu$1 AT rockall DOT cc DOT strath DOT ac DOT uk> NNTP-Posting-Host: hgty.capgemini.co.uk X-Trace: taliesin.netcom.net.uk 931429863 6331 194.42.240.2 (8 Jul 1999 10:31:03 GMT) X-Complaints-To: abuse AT corp DOT netcom DOT net DOT uk NNTP-Posting-Date: 8 Jul 1999 10:31:03 GMT X-Newsreader: Microsoft Outlook Express 4.72.3155.0 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Alan Wills wrote in message <7m1u1e$pnu$1 AT rockall DOT cc DOT strath DOT ac DOT uk>... >I have to read in this structure into a program. The problem is, the >compiler returns its size as 16 bytes when it should be 14 bytes. If I >change all the variables to unsigned short int then it gives 10 bytes (as it >should be). If I change the 2nd variable to unsigned short int it gives 12 >bytes (as it should be). But, if I change the last variable to unsigned >short int it gives 16 bytes as the total space occupied. Just what is going >on here? From the FAQ: `To produce faster code, GCC pads struct fields so that each field can be accessed without delays; this sometimes produces struct size which is larger than the sum of the sizes of its fields.' Read the FAQ for more details (section 22.10) Michael Stewart