Mail Archives: djgpp/1996/04/15/01:50:28
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:
>
> <source on>
>
> 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.)
- Raw text -