Is the way static data alligned correct?

Alexander Nedotsukov bland at FreeBSD.org
Sun Mar 14 23:01:51 PST 2004


Guys,

Recently doing some development I hit alignment problem on alpha 
machines. Problem solved but the way I did it in fact the reason why I 
asking pros to judge who is wrong here.
Inside code I have linked-in data blocks generated by external tool. 
They looks like this:
    const unsigned char raw_data_block[] = { bla-bla-bla };
Internal block content is 8 bytes aligned. Each block resides in a 
single .c file. So after compilation I have a set of .o files linked 
later into single shared object (library). Taking an address of such 
data block and casting it to pointer to some real structure was a 
problem because it is not necesary 8 byte aligned. Obvious solution was 
to ask explicitly for such alignment:
    const unsigned char raw_data_block[] __attribute__ ((alligned(8))) = 
{ bla-bla-bla };
But I wonder is this gcc bug or space optimization for char arrays only?

Thanks,
Alexander.


More information about the freebsd-alpha mailing list