[Issue 19516] Alignment of members & size of structs inconsistent with C

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Dec 26 16:56:28 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19516

--- Comment #2 from bdh_bugzilla at outlook.com ---

(In reply to kinke from comment #1)
> This is caused by how D treats *anonymous* nested structs and unions - their
> fields are correctly merged into the containing aggregate (alignment etc. is
> fine), but the tail padding of that nested struct/union isn't applied to the
> offsets of the following fields (which is most likely a bug).
> 
> I.e., this ugly workaround works as expected:
> 
> struct s {
>     static union U { double d; char[20] cs; }
>     U u;
>     char b;
>     alias u this;
> }
> pragma(msg, s.b.offsetof); // 24
> pragma(msg, s.sizeof);     // 32

Thanks for the quick reply and clarification of the issue. I'll be using the
workaround for now.

--


More information about the Digitalmars-d-bugs mailing list