Date: Mon, 15 Apr 1996 08:46:50 +0200 (IST) From: Eli Zaretskii To: Megens SA Cc: djgpp AT delorie DOT com Subject: Re: problem with packed structs In-Reply-To: Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Sun, 14 Apr 1996, Megens SA wrote: > I ran into the problem of aligned fields within a struct. I need to pack a > struct so it will have exactly the memory-layout I expect it to be (as > mentioned in the FAQ, section 22.9). I tried the example that was given in > the info-package about __attribute__((packed)), but although that should > work, it doesn't... > A small program I wrote to test it: > > > > struct foo > { > char a; > int x[2] __attribute__((packed)); > }; You should declare ALL the fields with the attribute, like this: struct foo { char a __attribute__((packed)); int x[2] __attribute__((packed)); }; and then it will work--unless you compile it as a C++ source, because GCC 2.7.2 has a known bug in the C++ compiler that prevents it from packing structures. (There is a work-around using pragmas, but if this is a C program, you don't want to know.)