From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: The size of structures and binary files Date: Fri, 13 Jun 1997 19:21:56 +0000 Organization: Two pounds of chaos and a pinch of salt Lines: 32 Message-ID: <33A19DD4.16BA@cs.com> References: <33A1B030 DOT 309E AT post DOT psychologie DOT uni-bielefeld DOT de> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp110.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk News Administrator wrote: > > Dear DJGPP users! > > Recently I came across something weird: > I have two structs: > struct s1 { char c1; char c2; short s}; > struct s2 { char c1; short s; char c2}; > > A call to sizeof will return 4 for s1 and 6 (!) for s2. > It seems like the size of the chars in s2 gets increased to 2. > > Does anybody know of a compiler option or some other way to get DJGPP > to use 1 byte chars regardless of their context? You should examine the FAQ (v2/faq210b.zip), chapter 22.9, for a detailed answer to this question. But in general, any 32-bit compiler will align variables for maximum efficiency in memory access. This sometimes means that struct members get padded to make them "line up" in memory correctly. You can use the gcc __attribute__ extension to turn off struct alignment, or use the less-recommended #pragma pack(1)...#pragma pack() solution. -- --------------------------------------------------------------------- | John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com | | * Proud user of DJGPP! * | http://www.cs.com/fighteer | | ObJoke: If Bill Gates were a robber, not only would he | | shoot you, but he'd send you a bill for the bullets. | ---------------------------------------------------------------------