Visual Studio Compilers(2005 through 2008) defines four macros for x86/x64 bit environment. Refer Predefined Macros
- _M_X64 Defined for x64 processors.
- _M_IX86 Defined for x86 processors. See the Values for _M_IX86 table below for more information. This is not defined for x64 processors.
- _WIN32 Defined for applications for Win32 and Win64. Always defined.
- _WIN64 Defined for applications for Win64.
Now on a x32 bit machine _M_X64 would never be set. On a 64 bit machine, if you are building on a 32 bit environment _M_X64 would be unset and _M_IX86 would be defined. _WIN32 is always defined irrespective of a 32/64 bit build.
Across all x64 processors, is there special significance of _M_X64? Can there be a scenario when _M_X64 is undefined when target is x64?
That’s not how it works. The compiler you use generates code for a specific target architecture, it doesn’t care about your machine. Generating x64 code on a 32-bit machine is very possible, MSVC includes a cross compiler that can run on a 32-bit operating system and generate code for x64. And it has a 64-bit compiler that generates x64 code. The IDE is setup to actually use the cross-compiler, regardless of your OS.
You can see these compilers installed on your machine, the
vc\binsubdirectory of the VS install directory. That directory contains a 32-bit compiler that generates x86 code. The x86_amd64 subdirectory has a 32-bit compiler that generates x64 code. The amd64 subdirectory has a 64-bit compiler that generates x64 code. Additional directories may exist there if you have compilers for ARM cores. Which are always cross-compilers.The macro names you ask about are predefined macros, the full list is here. The _M_X64 macro is always defined by any of the compilers that generate x64 code.