You've got all the steps right. An _AMD64_
symbol is not predefined by default by Visual Studio. You'll need to define it yourself if you want to use it:
#if defined _M_X64 || defined _M_AMD64
#define _AMD64_
#endif
But you're not making up the memory of its existence. The Windows DDK comes with makefiles that define this symbol, in addition to some others. Check in makefile.def
. The possibilities are:
_X86_
Variously known as x86, i386, and IA-32
(this is the same as VS's predefined _M_IX86
)
_AMD64_
Variously known as AMD64, x64, x86-64, IA-32e, and Intel 64
(this is the same as VS's predefined _M_X64
and _M_AMD64
)
_IA64_
Intel Itanium (IA-64)
(this is the same as VS's predefined _M_IA64
)
…and some others for architectures nobody targets anymore
Ideally, you would configure your build system to predefine a set of known macros that you will then use in your own code. If you don't have a build system, at least set something up in a precompiled header file. That way, you're not relying on implementation-dependent symbols everywhere, and switching compilers is not a colossal chore—the target architecture symbols predefined by GCC are very different from MSVC, for example.