Specifications

Chapter 4 Troubleshooting and Portability Issues 53
Compiler Usage Guidelines for AMD64 Platforms
32035 Rev. 3.22 November 2007
4.12.1 Run-Time Errors
Is your code causing buffer overruns that violate 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.12.2 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.
Does your program rely on some x87 features?
The /arch:SSE2 switch instructs the compiler to use SSE2 registers and instructions. If the results do
not match your expectations when using SSE2, the program may rely on some x87 features.
As a diagnostic step, try building the program using x87 operations for floating point computations
and see if the results are as expected. Omitting the /arch:SSE2 switch recommended in the general
performance guidelines causes the compiler to build the program using x87 operations for floating-
point computations.
Because omitting the /arch:SSE2 switch could degrade performance, the user should investigate the
precision requirements of the program. If the user has access to the source code, it may be possible to
adapt the algorithm to SSE2.
4.12.3 Program Gives Unexpected Results or Exception Behavior
Does your code depend on exact implementation of IEEE or ISO rules or specifications for floating-
point behavior?
Do not use /fp:fast optimization, as recommended in the general performance guidelines, in this case.
The compiler uses /fp:precise by default if no /fp switch is specified.
Does your code need structured and/or C++ exception handling?
Enable C++ exception handling with the appropriate /EH switch.
Are you to developing 32-bit code that you may eventually port to 64-bit code, and you would like the
code to remain compatible?
Use /Wp64 to detect 64-bit porting problems. This switch can be used with both 32-bit and 64-bit
Microsoft compilers.
On AMD64 architecture-based systems running the Microsoft Windows operating system, both int
and long are 32-bit, and pointers are 64-bit (P64). Do not use int or long for type-casting pointers.