Re: [Dev-C++] [Dev-C++]: Errors in structures
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Elias P. <eli...@ao...> - 2001-07-03 11:08:03
|
> 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
|