From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: Padding Question Date: Fri, 06 Dec 1996 20:24:12 -0800 Organization: Three pounds of chaos and a pinch of salt Lines: 42 Message-ID: <32A8F16C.596F@cs.com> References: <32A810D9 DOT 366E9B4E AT m-net DOT arbornet DOT org> <32A85B15 DOT 4015 AT skygames DOT com> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp222.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Kevin Baca CC: Rohit Jalan DJ-Gateway: from newsgroup comp.os.msdos.djgpp Kevin Baca wrote: > > Rohit Jalan wrote: > > > > Is it possible to stop gcc from padding structures ? > > > > #pragma pack(1) /* use one byte as minimum packing size */ #pragma is an evil, hackish way to make gcc pack structures. The DJGPP Frequently Asked Questions list (v2/faq202b.zip), chapter 22.9, tells you exactly how to go about packing structs in DJGPP, and refers you to the gcc reference which details the syntax of the __attribute__() extension. The following will cause gcc to pack the indicated structure to use the minimum possible amount of storage space: struct foo { int zork[3]; char name[33]; short stuff; long double total; } __attribute__((packed)); Note that there was a bug in the gcc compiler distributed with DJGPP v2.00 that caused struct packing to fail under C++, and it was this bug that prompted the use of #pragma pack(1) ... #pragma pack(). If you are writing C++ code in v2.00, you can use this method to make gcc pack correctly, but it is far better to upgrade to v2.01, which contains a fixed version of gcc in v2gnu/gcc2721b.zip. See the FAQ section 22.10 for more information. Good luck! -- --------------------------------------------------------------------- | John M. Aldrich, aka Fighteer I | fighteer AT cs DOT com | | Proud owner of what might one | http://www.cs.com/fighteer | | day be a spectacular MUD... | Plan: To make Bill Gates suffer | ---------------------------------------------------------------------