Differences between rel1 and rel3

Jason Perry jperry at hanover-square.freeserve.co.uk
Sun Sep 7 13:48:34 PDT 2003


In message <61665b2e4c.peter at chocky.org> you wrote:

Thanks for your response...

> > The reason is because of the way structures are packed is handled
> > differently between the two versions e.g.
> > 
> > struct data_desc {
> >   u_int8_t  Length;
> >   u_int8_t  Type;
> >   u_int16_t version;
> >   u_int8_t  CountryCode;
> >   u_int8_t  Number;
> > };
> > 
> > Under rel1, sizeof() reports six, but with rel3 it reports 20 presumably
> > because it is now allocating 4 bytes per member in memory.
> 
> Actually, the failure is the presumption on the part of the programmer,
> because C makes no promises about structure packing.
True,

> > I was wondering if there is a compiler switch or #pragma which would
> > make rel3 behave like rel1 in this respect as this is causing having in
> > a piece of code that otherwise works fine.
> 
> Yes, there is.  But since it's in the documentation, I'll let you find
> it yourself.  You can also put all the 8 bit quantities together.
Well, I'm glad to hear it's possible, but I'm not having any luck
finding it.

I've tried:

`-mstructure-size-boundary=<n>' where I've set <n> to 8
'-fpack-struct'

and lastly, using the __attribute__ ((packed)) for each member of the
structure.

In all of the above cases, sizeof(struct data_desc) returns 20 instead
of 6 which I get with rel1.

If you could point me in the right direction, I would be very grateful!

Cheers,

-- 
Jason Perry
Please note: This address filters out non-plain text emails



More information about the gcc mailing list