4

I created a new c++ project in VS2010. I added x64 as a new solution platform. I tried setting "copy settings from" to both "Win32" and "empty", but neither worked. _AMD64_ is not defined when I select x64 as the platform. Shouldn't it be? Is there another step I am unaware of for compiling for 64 bit?

In anticipation to questions: I am using VS2010 Ultimate, Windows 7 64bit, x64 compilers were selected during VS installation.

Baruch
  • 20,590
  • 28
  • 126
  • 201

1 Answers1

6

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.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574