64-Bit Compiler
Windows Driver Kit: Kernel-Mode Driver Architecture
64-Bit Compiler

The Microsoft Windows Driver Kit (WDK) includes a 64-bit build environment that you can use to evaluate your driver source code for the 64-bit version of Windows. This environment includes a 64-bit compiler that you can use to identify pointer truncation, improper type casts, and other 64-bit-specific problems. Better tools will be available in future releases, but this tool will get you started.

The first time you run the compiler, it will probably generate many pointer truncation or type mismatch warnings such as the following:

warning C4311: 'type cast' : pointer truncation from 'unsigned char *' to 'unsigned long '

Use these warnings as a guide to make your code more robust. It is good practice to eliminate all warnings, especially pointer-truncation warnings. For example, the following code can generate the C4311 warning:

buffer = (PUCHAR)srbControl;
(ULONG)buffer += srbControl->HeaderLength;

To correct the code, make the following changes:

buffer = (PUCHAR)srbControl;
(ULONG_PTR)buffer += srbControl->HeaderLength;

Predefined Macros

The compiler defines the following macros to identify the platform.

MacroMeaning
_WIN64A 64-bit platform.
_WIN32A 32-bit platform. This value is also defined by the 64-bit compiler for backward compatibility.
_WIN16A 16-bit platform.

The following macros are specific to the architecture.

MacroMeaning
_M_IA64A 64-bit Intel platform.
_M_IX86A 32-bit Intel platform.

Do not use these macros except with architecture-specific code. Instead, use _WIN64, _WIN32, and _WIN16 whenever possible.

64-Bit Compiler Switches and Warnings

There is a warning option to assist porting to 64-bit Windows. The -Wp64-W3 switch enables the following warnings:

  • C4305: Truncation warning. For example, "return": truncation from "unsigned int64" to "long."
  • C4311: Truncation warning. For example, "type cast": pointer truncation from "int*_ptr64" to "int."
  • C4312: Conversion to bigger-size warning. For example, "type cast": conversion from "int" to "int*_ptr64" of greater size.
  • C4318: Passing zero length. For example, passing constant zero as the length to the memset function.
  • C4319: Not operator. For example, "~": zero extending "unsigned long" to "unsigned _int64" of greater size.
  • C4313: Calling the printf family of functions with conflicting conversion type specifiers and arguments. For example, "printf": "%p" in format string conflicts with argument 2 of type "_int64." Another example is the call printf("%x", pointer_value); this causes a truncation of the upper 32 bits. The correct call is printf("%p", pointer_value).
  • C4244: Same as the existing warning C4242. For example, "return": conversion from "_int64" to "unsigned int," possible loss of data.


Send feedback on this topic
Built on November 19, 2009
© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View