Thread overview
[Issue 19516] Alignment of members & size of structs inconsistent with C
Dec 26, 2018
kinke@gmx.net
Dec 17, 2022
Iain Buclaw
December 26, 2018
https://issues.dlang.org/show_bug.cgi?id=19516

kinke@gmx.net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke@gmx.net

--- Comment #1 from kinke@gmx.net ---
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

--
December 26, 2018
https://issues.dlang.org/show_bug.cgi?id=19516

--- Comment #2 from bdh_bugzilla@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.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=19516

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

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

--- Comment #3 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19520

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--