Common: Add non-constant offsetof macro

This commit is contained in:
TellowKrinkle 2021-10-23 23:36:11 -05:00 committed by refractionpcsx2
parent 44f8317b7e
commit ed5a7802f3
1 changed files with 4 additions and 0 deletions

View File

@ -31,6 +31,10 @@
#include "common/emitter/x86_intrin.h"
// The C++ standard doesn't allow `offsetof` to be used on non-constant values (e.g. `offsetof(class, field[i])`)
// Use this in those situations
#define OFFSETOF(a, b) (reinterpret_cast<size_t>(&(static_cast<a*>(0)->b)))
// Renamed ARRAYSIZE to ArraySize -- looks nice and gets rid of Windows.h conflicts (air)
// Notes: I'd have used ARRAY_SIZE instead but ran into cross-platform lib conflicts with
// that as well. >_<