void initialization vs alignment holes

bearophile bearophileHUGS at lycos.com
Sat Mar 6 17:37:01 PST 2010


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 somthing.
> Is this correct?

That has to be correct.


> 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;
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list