www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Struct alignment

reply Johan Engelen <j j.nl> writes:
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
Sep 24 2017
next sibling parent EntangledQuanta <EQ universe.com> writes:
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?
Sep 24 2017
prev sibling parent reply kinke <noone nowhere.com> writes:
On Sunday, 24 September 2017 at 21:01:06 UTC, Johan Engelen wrote:
 So... what's correct? :-)
2.075+. ;) See https://github.com/dlang/dmd/pull/6754.
Sep 24 2017
parent Johan Engelen <j j.nl> writes:
On Sunday, 24 September 2017 at 21:21:27 UTC, kinke wrote:
 On Sunday, 24 September 2017 at 21:01:06 UTC, Johan Engelen 
 wrote:
 So... what's correct? :-)
2.075+. ;) See https://github.com/dlang/dmd/pull/6754.
Thanks kinke. (now on to fix LDC's codegen ;-)
Sep 24 2017