This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: G++ ignores -fpack-struct: bug?


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]