[Issue 22756] New: ImportC: no __builtin_offsetof
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Feb 10 10:47:09 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22756
Issue ID: 22756
Summary: ImportC: no __builtin_offsetof
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: ImportC
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dave287091 at gmail.com
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);
--
More information about the Digitalmars-d-bugs
mailing list