Mail Archives: djgpp/1997/01/05/10:15:04
On 4 Jan 1997, Roland Nilsson wrote:
> struct foo
> {
> 	char a;
> 	long b;
> } __attribute__((packed));
> 
> This will not compile - gcc thinks I forgot the ending ';', and it
> never recognizes the attribute. The error message:
> 
> foo.cc:5: semicolon missing after declaration of 'foo'
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));
};
> "packed:
>  This attribute, attached to an enum, struct, or union type definition, 
>  specified that the minimum required memory be used to represent the 
>  type. Specifying this attribute for struct and union types is equivalent 
>  to specifying the packed attribute on each of the structure or union 
>  members..."
Note that the above excerpt is from a Chapter called "C Extensions", not 
"C++ Extensions".
- Raw text -