Aligning on some odd address?
Fabian Cenedese
Cenedese@indel.ch
Thu Apr 16 07:15:00 GMT 2009
At 08:44 16.04.2009 +0200, you wrote:
>At 08:38 16.04.2009 +0200, Philipp Marek wrote:
>>Hello everybody,
>>
>>I'd like to know whether there's some way to get a structure aligned on a non-
>>aligned address.
>> struct {
>> unsigned char count;
>> struct something_else_t array[];
>> }
>>
>>Now I'd like to have the array (where each element has eg. 16, 32, or 48
>>bytes) aligned - on at least a 4 byte boundary, but better still on 8/16/64
>>bytes.
>
>Why don't you fill in dummy members to get the correct alignment?
>Like
>
> struct {
> unsigned char count;
> unsigned char dummy[7]; // for 8 byte alignment
> struct something_else_t array[];
> }
>
>You'd lose that memory anyway if the compiler aligns it himself.
I overlooked the packed requirement, but in that case you can just turn
it around:
struct {
unsigned char dummy[7]; // for 8 byte alignment
unsigned char count;
struct something_else_t array[];
}
Align the struct to 8 bytes and you have your array aligned to 8 bytes.
bye Fabi
More information about the Gcc-help
mailing list