Misc: Replace offsetof with constexpr-friendly OFFSETOF

Fixes build with clang-18.
This commit is contained in:
Stenzek
2024-04-28 14:25:34 +10:00
parent dc84c58c7c
commit 295081fe62
14 changed files with 144 additions and 138 deletions

View File

@ -46,9 +46,15 @@ char (&__countof_ArraySizeHelper(T (&array)[N]))[N];
#endif
#endif
// offsetof macro
#ifndef offsetof
#define offsetof(st, m) ((size_t)((char*)&((st*)(0))->m - (char*)0))
// offsetof macro. Need to use __builtin_offsetof(), otherwise it doesn't work in constant expressions.
#if defined(__clang__) || defined(__GNUC__)
#define OFFSETOF(st, m) __builtin_offsetof(st, m)
#else
#ifdef offsetof
#define OFFSETOF(st, m) offsetof(st, m)
#else
#define OFFSETOF(st, m) ((size_t)((char*)&((st*)(0))->m - (char*)0))
#endif
#endif
#ifdef __GNUC__