| November 24, 2008 11:00 PM PST | |
Address Win64* compilation warnings related to truncation. Most of the warnings that you encounter when compiling for Win64 are truncation-related warnings (conversion from INT64 to int). A truncation-related warning might look something like this:
C4311: Truncation warning</b> |
During the course of porting applications to the Win64 environment, it is necessary to identify and resolve compiler warnings and errors. The procedure for identifying these warnings and errors is addressed in the separate item "How to Use Makefiles to Resolve Win64 Porting Issues."
Cast the result to a proper data type or change the receiving variable to a scalable data type. Win64 uses the LLP64 (or P64) uniform data model, in which pointers and long long are 64 bits, but int and long are 32 bits. To support this data model and to provide compatibility with the existing Win32* code, new data types have been defined in Win64.
There are two ways to fix truncation-related warnings:
#1: Cast the result to a proper data type. Most of the non-pointer variables can be safely casted, as long as the result is guaranteed to be less than the maximum value that can be held in the casted data type. The following is a pointer-difference example of code in the error state:
char *start, *end // start and end of buffer |
Following is the modified code. Here we know that the difference (end-start) is less than 4 GB; hence it can be safely casted.
char *start, *end // start and end of buffer |
#2: Change the receiving variable to a scalable data type. By changing the receiving variables to a scalable data type, the same source code would work for 32-bit, as well as for Itanium® architecture. Scaling can cause a rippling effect where scaling a result would require several other variables and/or functions to be scaled. This will generate more warnings, which need to be addressed. The following error-state code uses variables receiving pointers:
char p |
Following is the modified code:
char p |
The following error-state code demonstrates passing parameters into functions:
void func(int s) |
Following is the modified code:
void func(INT_PTR s); // scale the variable |
Porting Microsoft Windows Applications to Intel® Itanium® Processor Systems
For more complete information about compiler optimizations, see our Optimization Notice.

