[Issue 23293] New: ImportC: Bit fields layout doesn't match C
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Aug 14 18:44:05 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23293
Issue ID: 23293
Summary: ImportC: Bit fields layout doesn't match C
Product: D
Version: D2
Hardware: All
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: kinke at gmx.net
This C code fails with DMD v2.100.1 on Linux x64:
```
struct S {
unsigned char a:7; // byte offset 0, bit offset 0
_Bool b:1; // byte offset 0, bit offset 7
_Bool c:1; // byte offset 1, bit offset 0
unsigned d:22; // byte offset 1, bit offset 1
_Bool e:1; // byte offset 4, bit offset 0 (wrong)
// should probably be: byte offset 3, bit offset 7
// or: byte offset 1, bit offset 23
};
_Static_assert(sizeof(struct S) == 4, "size != 4"); // 8 with DMD
```
The size is 4 with both latest clang and gcc on Linux:
https://cpp.godbolt.org/z/h4z938e5z
I haven't checked on Windows.
--
More information about the Digitalmars-d-bugs
mailing list