Differences between rel1 and rel3

Peter Naulls peter at chocky.org
Sun Sep 7 12:42:44 PDT 2003

In message <7c2b592e4c.jperry at hanover-square.freeserve.co.uk>
          Jason Perry <jperry at hanover-square.freeserve.co.uk> wrote:

> I have a piece of code which works fine when built with GCC rel1 but
> fails when built with GCC rel3.

You shoul avoid rel1 if at all possible.

> 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.

> 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.

Peter Naulls - peter at chocky.org        | http://www.chocky.org/
RISC OS C Programming                  | http://www.riscos.info/

More information about the gcc mailing list