Is there a simple preprocessor macro that is defined for a 64-bit build? I thought _WIN64
might have been it, but even when I build a 32-bit target, the parts enclosed in a #ifdef _WIN64 ... #endif
are compiled in, and this is causing problems. It's Friday and I can't think straight, but I'm sure I'm overlooking something very simple here. Maybe even something involving sizeof
.
相关问题
- Multiple sockets for clients to connect to
- the application was unable to start correctly 0xc0
- What is the best way to do a search in a large fil
- Inheritance impossible in Windows Runtime Componen
- glDrawElements only draws half a quad
The Visual C++ compiler defines the following macros:
Check your project's build properties, particularly the preprocessor section. Are you defining
_WIN64
somewhere inWIN32
builds? Thesizeof
thing probably won't work since you cannot use in a#if
test.I have always used _WIN64 to check if it is a 64 bit build.
N.B. _WIN32 is also always (automatically) defined by MSVC in 64 bit builds, so check for _WIN64 before you check for _WIN32:
It sounds like your problem might be related to a header or project setting improperly defining
_WIN64
- that should be left to the compiler.There's a subtle difference between
WIN64
and_WIN64
(at least for the Microsoft compilers - other compilers should follow suit, but not all do):_WIN64
is defined by the compiler when it's building a program for a Windows 64-bit platform. Note that this name is in the compiler implementor's namespace (leading underscore followed by a capital letter)WIN64
is defined by the Windows Platform SDK (or whatever they're calling it this year) when targeting a 64-bit platform.So if you're only including standard headers and don't take other measures to define it,
WIN64
will not be defined.There's a similar story for
_WIN32
andWIN32
- but checking other compilers: GCC 3.4.5 does defineWIN32
even if only standard headers are used. As does Digital Mars.Microsoft's compilers and Comeau do not.
Another bit of (hopefully) well known trivia is that
_WIN32
andWIN32
are set when targeting 64-bit Windows platforms. Too much stuff would have broken otherwise.