diff --git a/src/util/Cast.hxx b/src/util/Cast.hxx index d71fb593e..21075f1ce 100644 --- a/src/util/Cast.hxx +++ b/src/util/Cast.hxx @@ -53,7 +53,7 @@ template static constexpr inline ptrdiff_t ContainerAttributeOffset(const C *null_c, const A C::*p) { - return ptrdiff_t((const char *)null_c - (const char *)&(null_c->*p)); + return ptrdiff_t((const char *)&(null_c->*p) - (const char *)null_c); } template @@ -70,7 +70,7 @@ template static inline constexpr C & ContainerCast(A &a, const A C::*member) { - return *OffsetCast(&a, ContainerAttributeOffset(member)); + return *OffsetCast(&a, -ContainerAttributeOffset(member)); } /** @@ -80,7 +80,7 @@ template static inline constexpr const C & ContainerCast(const A &a, const A C::*member) { - return *OffsetCast(&a, ContainerAttributeOffset(member)); + return *OffsetCast(&a, -ContainerAttributeOffset(member)); } #endif