Date: Sun, 5 Jan 1997 17:01:52 +0200 (IST) From: Eli Zaretskii To: Roland Nilsson cc: djgpp AT delorie DOT com Subject: Re: __attribute__((packed)) on types In-Reply-To: <5amq4k$dvk@news.luth.se> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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".