www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23067] New: importC: offsetof macro assumes size_t is defined

https://issues.dlang.org/show_bug.cgi?id=23067

          Issue ID: 23067
           Summary: importC: offsetof macro assumes size_t is defined
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: ImportC
          Severity: minor
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: duser neet.fi
                CC: duser neet.fi

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

--
Apr 27 2022