Bug 22918 – importC: some types not zero-initialized in static variables
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-03-24T12:47:13Z
Last change time
2022-03-28T21:20:41Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
duser
Comments
Comment #0 by duser — 2022-03-24T12:47:13Z
char c;
double dbl;
enum E { a = 1, };
enum E myE;
int printf(char *, ...);
int main()
{
printf("%d\n", (int)c);
printf("%lf\n", dbl);
printf("%d\n", (int)myE);
return 0;
}
should print 0, 0.000000, 0, but prints 255, nan, 1
Comment #1 by duser — 2022-03-24T19:06:55Z
arrays initialized with the {0} syntax are also affected by this - C11 says the remaining elements should be initialized the same as "objects that have static storage duration"
int printf(char *, ...);
int main()
{
char ca[2] = {0};
printf("%d %d\n", (int)ca[0], (int)ca[1]);
return 0;
}
should print 0, 0, prints 0, 255
Comment #2 by dlang-bot — 2022-03-27T06:10:28Z
@WalterBright created dlang/dmd pull request #13893 "fix Issue 22918 - importC: some types not zero-initialized in static …" fixing this issue:
- fix Issue 22918 - importC: some types not zero-initialized in static variables
https://github.com/dlang/dmd/pull/13893
Comment #3 by dlang-bot — 2022-03-28T21:20:41Z
dlang/dmd pull request #13893 "fix Issue 22918 - importC: some types not zero-initialized in static …" was merged into master:
- c793b2e2a7d91894215c3dfdc2552578b4ee2f71 by Walter Bright:
fix Issue 22918 - importC: some types not zero-initialized in static variables
https://github.com/dlang/dmd/pull/13893