Bug 22994 – importC: some types not zero-initialized in static array
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-04-07T06:07:59Z
Last change time
2022-04-17T01:25:41Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
duser
Comments
Comment #0 by duser — 2022-04-07T06:07:59Z
issue 22918 still affects static arrays
char c[1];
double dbl[1];
enum E { a = 1, };
enum E myE[1];
int printf(char *, ...);
int main()
{
printf("%d\n", (int)c[0]);
printf("%lf\n", dbl[0]);
printf("%d\n", (int)myE[0]);
return 0;
}
should print 0, 0.000000, 0, but prints 255, nan, 1
Comment #1 by duser — 2022-04-11T16:42:40Z
test with more cases:
char cs1[1];
double ds1[1];
char cs[2] = {0};
double ds[2] = {0.0};
struct { char cs[2]; } css = { {0} };
struct { double ds[2]; } dss = { {0} };
union { char cs[2]; } csu = { {0} };
union { double ds[2]; } dsu = { {0} };
int printf(char *, ...);
int main()
{
printf("%d\n", (int)cs1[0]);
printf("%lf\n", ds1[0]);
printf("%d\n", (int)cs[1]);
printf("%lf\n", ds[1]);
printf("%d\n", (int)css.cs[1]);
printf("%lf\n", dss.ds[1]);
printf("%d\n", (int)csu.cs[1]);
printf("%lf\n", dsu.ds[1]);
printf("%d\n", (int)((char[2]){0})[1]);
printf("%lf\n", ((double[2]){0})[1]);
return 0;
}
enums aren't affected anymore, they seem to have been fixed for good
Comment #2 by dlang-bot — 2022-04-15T09:18:13Z
@WalterBright created dlang/dmd pull request #13985 "fix Issue 22994 - importC: some types not zero-initialized in static …" fixing this issue:
- fix Issue 22994 - importC: some types not zero-initialized in static array
https://github.com/dlang/dmd/pull/13985
Comment #3 by dlang-bot — 2022-04-17T01:25:41Z
dlang/dmd pull request #13985 "fix Issue 22994 - importC: some types not zero-initialized in static …" was merged into master:
- 3ba8f6721954d1111ef8c8f4e740f890cc0c54fc by Walter Bright:
fix Issue 22994 - importC: some types not zero-initialized in static array
https://github.com/dlang/dmd/pull/13985