Specifications

Chapter 4 Troubleshooting and Portability Issues 47
Compiler Usage Guidelines for AMD64 Platforms
32035 Rev. 3.22 November 2007
4.6 Microsoft
®
Compilers for (64-Bit) Microsoft
®
Windows
®
This section addresses errors and unexpected results that may be encountered when using 64-bit
Microsoft
®
compilers for Microsoft Windows
®
.
4.6.1 Compilation Errors
Does your code suffer from 64-bit portability issues such as type-casting pointers to int or long?
Use the /Wp64 switch to detect 64-bit porting problems. This switch can be used with both 32-bit and
64-bit Microsoft compilers. (This switch is on by default for the 64-bit compiler.)
On AMD64 architecture-based systems running the Microsoft Windows operating system, both int
and long are 32 bits (P64), and pointers are 64 bits. Do not use int or long for type-casting pointers.
Use portable, scalable data types like INT_PTR, UINT_PTR, LONG_PTR, and ULONG_PTR for
type-casting pointers.
Note: Data types INT_PTR, UINT_PTR, LONG_PTR, and ULONG_PTR are Microsoft specific
data types.
Issues such as these can be detected by using the /Wp64 switch.
4.6.2 Run-Time Errors
Is your code causing buffer overruns and thus violating security?
Turn on the /GS switch. Turning on the /GS switch causes the Microsoft compiler to generate
additional security code, such as bounds checking.
4.6.3 Compiled and Linked Code Generates Unexpected Results
Does your program depend on precise floating-point behavior?
Do not use the /fp:fast switch recommended in the general performance guidelines. When the fp:fast
mode is enabled, the compiler relaxes the rules that fp:precise uses when optimizing floating-point
operations. This mode allows the compiler to further optimize floating-point code for speed at the
expense of floating-point accuracy.
4.6.4 Program Gives Unexpected Results or Exception Behavior
Does your code depend on the exact implementation of IEEE or ISO rules or specifications for
floating-point behavior?
Do not use the /fp:fast switch recommended in the general performance guidelines. The compiler
uses /fp:precise by default if no /fp switch is specified.
Does your code need C++ exception handling?