Mail Archives: djgpp/1997/01/05/18:21:28
In article <Pine DOT SUN DOT 3 DOT 91 DOT 970105165834 DOT 22565A-100000 AT is>, eliz AT is DOT elta DOT co DOT il
says...
>
>
>On 4 Jan 1997, Roland Nilsson wrote:
>
>> struct foo
>> {
>> char a;
>> long b;
>> } __attribute__((packed));
>>
[...]
>
>This doesn't work for C++ programs, AFAIK. In C++, you need to declare
>each struct field with __attribute__((packed)), like so:
>
>struct foo
>{
> char a __attribute__((packed));
> long b __attribute__((packed));
>};
Oh. Now it works, thanks. Only problem is that the structure size
still is expanded to a 4-byte boundary; The above structure would
have foo::a at offset 0, foo::b at 1, but sizeof(foo) returns 8.
But alright, this _is_ mentioned in the GCC manual. (Using the
-fpack-struct argument yields sizeof(foo) = 5, however.)
>> "packed:
>> This attribute, attached to an enum, struct, or union type definition,
>> [...]
>
>Note that the above excerpt is from a Chapter called "C Extensions", not
>"C++ Extensions".
Oops. I incorrectly assumed that C and C++ programs behaves identically.
Sorry.
- Raw text -