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, regardless of how A is defined (member variable types, alignment, etc.)? More to the point, say I have a function foo() which looks like this:

    extern(C) void foo(A* ptr, size_t len);

Is it now guaranteed that I can safely pass it a pointer to an array of Bs? That is,

    auto arr = new B[10];
    foo(cast(A*) arr.ptr, arr.length);

Thanks,
Lars
  • Struct size Lars T. Kyllingstad via Digitalmars-d-learn

Reply via email to