struct field alignment

Robert Jacques sandford at jhu.edu
Thu Oct 21 19:55:09 PDT 2010


On Sun, 17 Oct 2010 23:38:34 -0400, Walter Bright  
<newshound2 at digitalmars.com> wrote:

> Robert Jacques wrote:
>> Although I have a solution that works well for me, the one thing I  
>> lament about not having a canonical D way of expression  
>> align(8)/align(16), even at only a meta-information level, is that if  
>> phobos gets a small vector library, I can't use it and conversely I'm  
>> not motivated to improve/submit my own small vector library to phobos.
>
> I'm painfully aware that align(8)/(16) don't work on the 32 bit targets.  
> I've been reluctant to fix that because it involves some performance  
> degradation (keeping the stack so aligned requires the insertion of  
> stack adjustment instructions here and there).
>
> With the 64 bit target, however, the C ABI will force the issue. It'll  
> support those alignments.

Cool. I understand the performance issue, but would it be possible for the  
internal alignment of a struct to be correct? i.e. struct A { float x;  
float2 point; } would be properly aligned internally: struct A { float x;  
int padding; float2 point; }. That way, 32-bit programs could read binary  
files from 64-bit programs and vice-versa.


More information about the Digitalmars-d mailing list