Re: Off-topic

Hans Lermen (lermen@elserv.ffm.fgan.de)
Thu, 6 Mar 1997 10:27:53 +0100 (MET)


On Wed, 5 Mar 1997, Mike Kilburn wrote:

> > __attribute__((packed))
>
> Does not work. (2.7.2)

Does, if you pack the whole structure.

The below example

struct pak {
char byte;
long dword;
} __attribute__((packed));

xxx (struct pak *pak) {
return sizeof(*pak);
}

Compiled with (gcc-2.7.2.1)

# gcc -S -O2 packed.c

Gives

xxx:
pushl %ebp
movl %esp,%ebp
movl $5,%eax
^^^^

which is (what I guess) just what you want ( sizeof(char) + sizeof(long) ).

Packing the whole structure leads to byte alignment for all members within
the structure, hence you are free to privately align by inserting dummy
byte variables into the structure.

Hans
<lermen@fgan.de>