Bug 23067 – importC: offsetof macro assumes size_t is defined
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-04-28T06:55:03Z
Last change time
2022-05-12T04:13:49Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
duser
Comments
Comment #0 by duser — 2022-04-28T06:55:03Z
the __builtin_offsetof macro in druntime uses size_t to cast the result type, but size_t isn't a built-in type in C so it only works after the type has been defined
struct S { int x; };
//int y = __builtin_offsetof(struct S, x);
int y = ((size_t)((char *)&((struct S *)0)->x - (char *)0));
test.c(3): Error: undefined identifier `size_t`
when the typeof() PR is merged, this can be fixed by using "typeof(sizeof(0))" to get the size_t type in the macro
Comment #1 by dlang-bot — 2022-05-12T03:06:25Z
@WalterBright created dlang/druntime pull request #3819 "fix Issue 23067 - importC: offsetof macro assumes size_t is defined" fixing this issue:
- fix Issue 23067 - importC: offsetof macro assumes size_t is defined
https://github.com/dlang/druntime/pull/3819
Comment #2 by dlang-bot — 2022-05-12T03:49:52Z
dlang/druntime pull request #3819 "fix Issue 23067 - importC: offsetof macro assumes size_t is defined" was merged into master:
- 469d67061474837b46fbd3a0037db7170d174ca6 by Walter Bright:
fix Issue 23067 - importC: offsetof macro assumes size_t is defined
https://github.com/dlang/druntime/pull/3819
Comment #3 by bugzilla — 2022-05-12T04:13:49Z
It works now if you #include "importc.h". This will become automatic soon.