How to use #ifdef to differentiate 64bit and 32bit
If you want to use the _WIN64, _WIN32 macros, list the _WIN64 one first.
#if defined _WIN64
#elif defined _WIN32
_WIN32 is defined for both 32 and 64 bit projects so you know that it will always be defined on a MSVC build.
_WIN64 on the other hand is only defined with a 64 bit compiler. So putting 64 first eliminates the need to check for both at once.
The final else is there for if your code is ever built with a different compiler which doesn’t predefine _WIN32 or _WIN64.
This way you can provide an option for that, but if you know it will never be built besides an MSVC compiler then you can just remove it.
crescens2k – http://c2kblog.blogspot.com/