How do I use _W64 and __w64 in VC++?
There's such thing as __w64 in Visual C++ 9. I came across it while trying to port my native C++ DLL to 64 bit. In particular in crtdefs.h
there's this nice snippet:
#if !defined(_W64)
#if !defined(__midl) && (defined(_X86_) || defined (_M_IX86)) && _MSC_VER >= 1300
#define _W64 __w64
#else
#define _W64
#endif
#endif
which if I get it right implies that for 64 bit _W64 is defined as an empty string and has no effect, but for 32 bit it is defined as __w64
.
I tried defining _W64 to be an empty string and __w64开发者_如何学C
in turn and at least both time the project compiles fine in 64-bit configuration.
That said both _W64
and __w64
look useless. How am I intended to use them and how should I define _W64
in 64-bit projects?
__w64
was used to mark types that have different sizes in 32bit and 64bit environments. The compiler could then issue a warning when you assigned a maybe-64bit-type to a 32bit-type.
If you switch the MSDN: __w64 view to the newest version, you can see that the keyword is deprecated. VC9 even generates a warning when you try to compile with the /Wp64 option.
The answer is, you don't. It's a compiler feature for use by the 32 bits compiler. The original idea was that Microsoft wanted to prepare programmers for the upcoming 32->64 bits transition. Therefore, the 32 bits compiler gained the ability to label certain typedefs as __w64. Microsoft then used that ability to label typedefs that would change in Win64.
精彩评论