From: j DOT aldrich6 AT genie DOT com Message-Id: <199604160421.AA017318484@relay1.geis.com> Date: Tue, 16 Apr 96 04:10:00 UTC 0000 To: djgpp AT delorie DOT com Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Subject: Re: problem with packed struct Reply to message 2225083 from ELIZ AT IS DOT ELTA. on 04/15/96 2:46AM >You should declare ALL the fields with the attribute, like this: > > struct foo > { > char a __attribute__((packed)); > int x[2] __attribute__((packed)); > }; There's an easier way to do that: struct foo { char a; int x[2]; } __attribute__((packed)); Just put the __attribute__ at the end of the struct definition, and all its fields are packed automatically. I had to do something like this for a program that would be compiled on both DJGPP and Turbo C. I made all my ints short, and closed the struct definition with: #if defined(GNUC) } __attribute__((packed)); #else }; #endif Thus, the resulting structures could be stored by fread() in a format compatible between both 32-bit and 16-bit compilers, and my data files wouldn't have to be rewritten every time I switched. John