Need to change the default alignment of a data type
Tue Jan 13 16:45:00 GMT 2009
Rossi, Peter J wrote:
> Is there a way to globally change the default alignment for a data type, in particular type double?
> I am working on a project porting C code from AIX (xlC 7.0) to Linux (gcc 4.1.1) where the code will continue run on both platforms so there needs to be consistency with the size and alignment of various structs that get passed around. For example,
> typedef struct_msg
> int header;
> double value;
> } MY_MESSAGE;
> On AIX, the xlC compiler aligns the double in this struct to a 4 byte boundary however, Linux gcc aligns it on an 8 byte boundary. The result is on AIX the struct has size of 12 with the double at offset +4 while on Linux the struct has size of 16 with the double at offset +8. When the struct is passed as part of a message between the two platforms, the double is not accessed properly on the other platform.
> Yes, I know I can use the __attribute__ ((aligned(4))) with the double but this would have to be done EVERYWHERE that a struct like this is declared which is not really practical for us to do.
> What we are looking for is a way for the compiler to globally know that all type double should be aligned on 4 byte boundary (the same as how AIX xlC is doing it). The ideal solution is some option or other directive that I have not been able to locate yet, or worse case, could our 'gcc' be recompiled to use a different alignment for type double?
This is impossible because the layout of structures is part of the system ABI.
Sure, it would work for your code, but not for any code in a system library
that you called.
More information about the Gcc-help