Bug 22236 – sizeof an empty C struct should be 0, not 1
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-08-24T08:18:59Z
Last change time
2021-09-07T22:52:04Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
Walter Bright
Comments
Comment #0 by bugzilla — 2021-08-24T08:18:59Z
To match typical C compiler behavior. (The sizeof is 1 for C++.)
The following program will print 0 for C, 1 for C++. D currently regards both as 1.
#include <stdio.h>
struct S { };
int main() {
printf("%d\n", sizeof(struct S));
}
Comment #1 by dlang-bot — 2021-08-24T08:38:56Z
@WalterBright created dlang/dmd pull request #13009 "fix Issue 22236 - sizeof an empty C struct should be 0, not 1" fixing this issue:
- fix Issue 22236 - sizeof an empty C struct should be 0, not 1
https://github.com/dlang/dmd/pull/13009
Comment #2 by dlang-bot — 2021-08-25T05:55:59Z
dlang/dmd pull request #13009 "fix Issue 22236 - sizeof an empty C struct should be 0, not 1" was merged into master:
- d3a3e01e493cf260a5eef745c4700f367eedd310 by Walter Bright:
fix Issue 22236 - sizeof an empty C struct should be 0, not 1
https://github.com/dlang/dmd/pull/13009
Comment #3 by dlang-bot — 2021-09-02T00:59:47Z
dlang/dmd pull request #13037 "[stable] Cherry-pick bit-field fixes from master" was merged into stable:
- 83bad681cf4ca898ee24659cf9e912166c9a637b by Walter Bright:
fix Issue 22236 - sizeof an empty C struct should be 0, not 1
https://github.com/dlang/dmd/pull/13037
Comment #4 by dlang-bot — 2021-09-07T22:52:04Z
dlang/dmd pull request #13053 "merge stable" was merged into master:
- 41a91bf900f9a8d2e7f53c115e927485284c7b14 by Iain Buclaw:
[stable] Cherry-pick bit-field fixes from master (#13037)
* ImportC: static initializers for bit fields
* Define TargetC.BitFieldStyle to support different implementations of bit fields
* fix Issue 22236 - sizeof an empty C struct should be 0, not 1
* ImportC: add support for Posix bit fields
* ImportC add Posix bitfield support
* fix Issue 22245 - importC: Error: found `.` when expecting `)`
* ImportC: posix bit field layout
* ImportC: implement Microsoft bitfield layout
* fix Issue 21969 - importC: Error: bit fields are not supported
* ImportC: add Digital Mars C bitfield support
Co-authored-by: Walter Bright <[email protected]>
https://github.com/dlang/dmd/pull/13053