diff --git a/src/System/Types.hpp b/src/System/Types.hpp index 165df56b2..f0f392342 100644 --- a/src/System/Types.hpp +++ b/src/System/Types.hpp @@ -201,7 +201,10 @@ inline constexpr float4 replicate(float f) return vector(f, f, f, f); } -#define OFFSET(s, m) (int)(size_t) & reinterpret_cast((((s *)0)->m)) +// The OFFSET macro is a generalization of the offsetof() macro defined in . +// It allows e.g. getting the offset of array elements, even when indexed dynamically. +// We cast the address '32' and subtract it again, because null-dereference is undefined behavior. +#define OFFSET(s, m) ((int)(size_t) & reinterpret_cast((((s *)32)->m)) - 32) } // namespace sw