This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: G++ ignores -fpack-struct: bug?
- To: osv at Javad dot RU
- Subject: Re: G++ ignores -fpack-struct: bug?
- From: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Sat, 20 Feb 1999 14:46:32 +0100
- CC: egcs-bugs at cygnus dot com
- References: <873e41grtm.fsf@osv.javad.ru>
> osv@osv$ cat pack.cc
> struct A {
> char c;
> int i;
> } a;
>
> The size of this struct if packed should be 5 bytes, and C compiler
> gives exactly this. C++ compiler, however, gives 8 bytes both with and
> without -fpack-struct.
Thanks for your report. It seems you are right: g++ does not care at
all about the setting of flag_pack_struct.
As a work-around, you could declare the structures explicitly packed:
struct __attribute__((packed)) A {
char c;
int i;
} a = {'x', 42};
Unless you have a very specific application, the is the better way:
-fpack-struct also effects structures which might not need packing.
Regards,
Martin