Struct alignment

EntangledQuanta EQ at universe.com
Sun Sep 24 21:09:42 UTC 2017


On Sunday, 24 September 2017 at 21:01:06 UTC, Johan Engelen wrote:
> DMD <= 2.074  and DMD >= 2.075 disagree on struct alignment.
>
> ```
> struct UInt {
> align(1):
>     uint a;
> }
>
> struct Bug {
>     ubyte one;
>     UInt two;
> }
>
> static assert(Bug.two.offsetof == 4); // Error DMD>=2.075, 1 == 
> 4 is false
> static assert(Bug.sizeof == 8); // Error DMD>=2.075, 5 == 8 is 
> false
>
> align(1)
> struct Align1UInt {
> align(1):
>     uint a;
> }
>
> struct BugAlign1 {
>     ubyte one;
>     Align1UInt two;
> }
>
> static assert(BugAlign1.two.offsetof == 1);
> static assert(BugAlign1.sizeof == 5); // Error DMD<=2.074, 8 == 
> 5 is false
> ```
>
> So... what's correct? :-)
>
> Cheers,
>   Johan

Don't worry, this isn't a bug! It's a feature! It will just make 
your programs run faster! It won't get fixed! Don't want to break 
backwards compatibility, do we?



More information about the Digitalmars-d mailing list