C11 defines a standard macro `offsetof` (which is defined in 7.19 in the definition of what is in the <stddef.h> header). Clang implements this with a compiler intrinsic `__builtin_offsetof`. I can’t find a clang reference, but it just does what the macro would do. The following C code: // off.c #include <stddef.h> struct Foo { int x; }; int y = offsetof(struct Foo, x) Expands to: // off.i struct Foo { int x; }; int y = __builtin_offsetof(struct Foo, x); which dmd rejects, as it can’t handle the __builtin_offsetof. The above is the simplest case, the following is also allowed: struct Foo { struct { int x; } y; }; int y = __builtin_offsetof(struct Foo, y.x);
@WalterBright updated dlang/druntime pull request #3736 "fix Issue 22756 - ImportC: no __builtin_offsetof" fixing this issue: - fix Issue 22756 - ImportC: no __builtin_offsetof https://github.com/dlang/druntime/pull/3736
dlang/druntime pull request #3736 "fix Issue 22756 - ImportC: no __builtin_offsetof" was merged into master: - cd85cb0bbf4674d774e88161cdbbd70422aaacbd by Walter Bright: fix Issue 22756 - ImportC: no __builtin_offsetof https://github.com/dlang/druntime/pull/3736
The above PR defines a “__builtin_offset”, not a “__builtin_offsetof”.
@WalterBright created dlang/druntime pull request #3739 "fix Issue 22756 - ImportC: no __builtin_offsetof" fixing this issue: - fix Issue 22756 - ImportC: no __builtin_offsetof https://github.com/dlang/druntime/pull/3739
dlang/druntime pull request #3739 "fix Issue 22756 - ImportC: no __builtin_offsetof" was merged into master: - b917bc143c58485ade6dbad5ca0dd6e8efd74bf5 by Walter Bright: fix Issue 22756 - ImportC: no __builtin_offsetof https://github.com/dlang/druntime/pull/3739