Re: [PATCH] optional explicit sb-alien struct alignment
James Y Knight <foom <at> fuhm.net>
2005-10-03 17:38:22 GMT
On Oct 3, 2005, at 12:25 PM, Cyrus Harmon wrote:
>> Since compiler writers don't use completely random alignment rules,
>> it might be better to have one :maximum-alignment key for the whole
> Yes, this might be a better approach for this particular problem.
> This route seemed more expedient, but I'm open to suggestions on
> how to handle this as you describe.
In GCC, at least, you can specify the minimum alignment, both on the
structure itself, and on each data member individually. Setting the
alignment on the structure affects its placement in other structures
(but doesn't affect the data members inside it), and setting the
alignment of its data members affects that member (and by
implication, the default alignment of the struct as a whole). The
specified alignment doesn't override the normal rules for alignment,
and thus you can only increase the alignment. If you want to decrease
it, you must additionally use the "packed" attribute, which gets rid
of the default minimum alignment.
Thus, it seems best to allow the ability to specify alignment on each
member individually in the alien API, as well.
Also, while compiler writers may not use _completely_ random
alignment rules, it almost seems that way on PPC. A double will have
8-byte alignment iff it is the first element in the struct. In any