using the offsetof macro from importc.h:
typedef unsigned long size_t;
struct S { char text[4]; };
//int tmp = __builtin_offsetof(struct S, text[0]);
int tmp = ((size_t)((char *)&((struct S *)0)->text[0] - (char *)0));
Error: dereference of invalid pointer `cast(S*)0LU`
the fix for issue 22809 didn't affect this
Comment #1 by dlang-bot — 2022-03-30T08:03:25Z
@WalterBright created dlang/dmd pull request #13925 "fix Issue 22935 - importC: offsetof with array element gives 'derefer…" fixing this issue:
- fix Issue 22935 - importC: offsetof with array element gives 'dereference of invalid pointer'
https://github.com/dlang/dmd/pull/13925
Comment #2 by dlang-bot — 2022-03-31T08:23:22Z
dlang/dmd pull request #13925 "fix Issue 22935 - importC: offsetof with array element gives 'derefer…" was merged into master:
- 10a7ee5bd5e8f4572ae9864dbba7ea6ab733edf4 by Walter Bright:
fix Issue 22935 - importC: offsetof with array element gives 'dereference of invalid pointer'
https://github.com/dlang/dmd/pull/13925