Architecture-generic InterlockedIncrement for 32/64-bit

633 Views Asked by At

What is the best way to use the C++ InterlockedIncrement functionality generic to both 32-bit and 64-bit architectures? (There are separated functions)

Is there a better way than using the #if _W64 preprocessor command?

1

There are 1 best solutions below

1
MSalters On

The easiest solution, since you're using C++:

inline LONGLONG __cdecl InterlockedIncrement(LONGLONG volatile *Addend)
{
  return InterlockedIncrement64(Addend);
);

Now you can unconditionally call InterlockedIncrement on either 32 bits or 64 bits variables, in both 32 and 64 bits builds.