Re: [Dev-C++] [Dev-C++]: Errors in structures
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Vassili <v.v...@bt...> - 2001-07-03 18:17:56
|
This is due to the compiler aligning members at addresses that are multiples
of 8 bytes. You'll find the something happens if you use classes.
----- Original Message -----
From: "Elias Pschernig" <eli...@ao...>
To: <dev...@li...>
Sent: Tuesday, July 03, 2001 12:07 PM
Subject: Re: [Dev-C++] [Dev-C++]: Errors in structures
> > It is not a bug, it is compiler feature. For some optimizations some c++
> > compilers adjust the size of structue to the multiple of 8.
> >
>
> I think it is only a multiple of 4. The reason is that the compiler you
are
> using is for a 32bit processor. You will find the same thing on any other
> compiler which outputs 32bit object code as well. (A 64bit processor
> probably will use 8 byte.) The reason for this is, for a 32-processor the
> memory is just a block of 32 bit long units, and 32 bits are 4 bytes. So
> every variable (even structs) should start on a 4 bytes boundary. That's
> why they have to be aligned to the length of a multiple of 4 bytes.
>
> To turn the alignment of structs off in mingw, try this (the code will
> not be portable anymore then though, because if you compile with another
> compiler like MSVC, it won't recognize it):
>
> struct mystruct {
> char a;
> int b;
> } __attribute__((packed)) c;
>
> sizeof(c) should now be 5, one char (1) and one int (4).
>
> Regards,
>
> Elias Pschernig
>
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|