Alignment of unions

Christopher Wright dhasenan at gmail.com
Tue Apr 14 15:36:09 PDT 2009


Stewart Gordon wrote:
> Don wrote:
>> Stewart Gordon wrote:
> <snip>
>>> That's only because you want to be able to attach alignments to 
>>> individual members of a union.  And I still don't know why.
>>
>> I'm not sure why you think unions are so different to structs. They 
>> are identical in most respects -- including requirements for alignment 
>> of members.
> 
> I still don't know what you mean.
> 
>>> If you want a union to have a certain alignment relative to a struct 
>>> in which it's contained, in what cases is it not sufficient to put 
>>> the align attribute on the union's instance in the struct?
>>
>> In cases where you don't know what the containing struct is. The union 
>> may just be a type returned from a template, for example.
> 
> If you don't know what the containing struct is, you probably also don't 
> know what member alignment that struct requires.  The person who creates 
> the struct, OTOH, does know.  So why are you trying to do that person's 
> job?
> 
> Stewart.

You know ahead of time that you're going to use this union everywhere 
and that it should have proper alignment. If you still want to put the 
align attribute everywhere it's used instead, allow me to shoot you.

Granted, you can replace your named union with a struct of the same name 
containing an anonymous union, and put the align attribute on that. That 
wouldn't be too odious (as long as the language specification mentioned 
the workaround), but since you already have align for unions, why bother 
changing it?



More information about the Digitalmars-d mailing list