www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22756] New: ImportC: no __builtin_offsetof

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 puremagic.com
          Reporter: dave287091 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);

--
Feb 10 2022