Both are used for storing addresses and doing pointer arithmetic, both are defined in WinAPI, when should I use a uintptr_t (cstdint) vs a DWORD_PTR (Windows.h)? Both are 32bits and 64bits in x86 and x86_64 respectively
A
DWORD_PTRis anunsigned longtype used for pointer precision. It is used when casting a pointer to anunsigned longtype to perform pointer arithmetic.DWORD_PTRis also commonly used for general 32-bit parameters that have been extended to 64 bits in 64-bit Windows.
I do not intend for my code to be portable, I'm stuck with WinAPI. What type is the best use case?
Prefer
uintptr_tit is part of the C++ standard as of C++11 and later. DWORD_PTR is specific to Visual C++ and is therefore not portable.While Visual C++ may choose to implement
uintptr_tas aDWORD_PTRorunsigned longunder the hood, that is up to them to do, you are safer sticking to the standard library.