Struct size

Andrej Mitrovic via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 19 05:26:03 PDT 2014


On 4/19/14, Lars T. Kyllingstad via Digitalmars-d-learn
<digitalmars-d-learn at puremagic.com> wrote:
> Say I have two structs, defined like this:
>
>      struct A { /* could contain whatever */ }
>
>      struct B { A a; }
>
> My question is, is it now guaranteed that A.sizeof==B.sizeof?

The best thing to do is add a static assert and then you can relax:

-----
struct A { }
struct B { A a; }
static assert(A.sizeof == B.sizeof);
-----

As for the ABI, I don't think I've ever seen it mentioned anywhere.


More information about the Digitalmars-d-learn mailing list