void initialization vs alignment holes

strtr strtr at spam.com
Sat Mar 6 21:39:50 PST 2010


bearophile Wrote:

> strtr:
> 
> > I suspect this isn't the case for void initialization; if my struct has some alignment hole I better not void initialize it if ever I want to compare it with something.
> > Is this correct?
> 
> That has to be correct.
Might this be worth an explicit mention on digitalmars?

> 
> 
> > Would you ever have an alignment hole if all the struct contains are basic types(excluding bool)?
> 
> On Windows the sizeof of this struct is 16 bytes, so there is a big hole in the middle:
> 
> struct Foo {
>   short s;
>   double d;
> }
> 
> This is 12 bytes long, it has a smaller hole, even if the data needs the same space, because doubles need a stronger alignment:
> 
> struct Foo {
>   short s;
>   int[2] i;
> }
> 

I should have thought of that, thanks ;)

Suppose I'd still would like to use void optimizations, how do you clear the holes manually?
align(1) and add a dummy member initialized to 0 to fill?
Or would this not be an optimization any more because the way dmd aligned it optimally for the registers (or something) ?

Not that I'm touching void any more, just interested :)




More information about the Digitalmars-d-learn mailing list