Mail Archives: djgpp/1997/03/19/15:26:14
"Ian Mausolus" <mausolus AT ican DOT net> wrote:
> Can someone please tell me what the following satements do and how to use
> them? As well, what is the difference between them?
>
> 1) #pragma pack(...)
> 2) __attribute__((packed))
>
GCC alignes all the data so the members of an struct are aligned to 32 bits
boundaries. For example
struct
{
char a;
int b;
} foo;
will use 8 bytes of memory, a will be in the offset 0 and b in the offset 4,
but if you use the packed attribute b will be at offset 1 (be carreful foo will
still using 8 bytes).
Under plain C the attribute is enough but under C++ there are a bug in the
C++ front-end and you need to enclose the declaration with the above pragma.
SET
--------------- 0 --------------------------------
Salvador Eduardo Tropea (SET).
Address: Curapaligue 2124, Caseros, 3 de Febrero
Buenos Aires, (1678), ARGENTINA
TE: +(541) 759 0013
- Raw text -