Question about -ansi flag, and different size of struct from C and C++

Leon Pollak leonp at
Mon Dec 15 12:46:23 UTC 2003

On Monday 15 December 2003 14:36, Ralf Corsepius wrote:
> On Mon, 2003-12-15 at 13:02, Oleg Ivanov wrote:
> >     Hello list,
> >     I have a problem. I defined struct like:
> >         struct dummy {
> >           int var1;
> >           short var2;
> >           int var3;
> >        } __attribute__ ((packed));
> >
> >     and access to it from C and C++ code.
> >     The problem is that size from C is 10 bytes and from C++ is 12
> > bytes, I couldn't make that C++ packed that struct, exept removing -ansi
> > flag from compiler string.
> >     So I have two question, is there another method to ask C++ packed
> > struct,
> __attribute__ is a gcc extension,
> #pragma Packed rsp. __attribute__((packed)) are compiler-dependent
> features,
> "packing" in general is target dependent.
I am too small to argue with Ralf therefore I ask: which target will interpret 
the "packed" pragma different from "without holes, byte by byte"? I was sure 
that this means the same everywhere...

> In one sentence: Don't do that! ;)
And how to declare the HW dependent structures?

> I don't know why gcc accepts __attribute__((packed)) and g++ doesn't.
> IMO, gcc and g++ should both either refuse to take this code if using
> -ansi or silently not pack.
Here I can say - I use "packed" in C++ and it works, I don't know why this 
does not work in your case. Look for some other causes.

> Ralf
leonp at plris dot com

More information about the users mailing list