Support Hex Constants on 64-Bit Intel Architecture

Submit New Article

March 10, 2009 9:00 PM PDT



Challenge

Modify code to support the use of integer-constant-type suffixes on 64-bit Intel® architecture. If a piece of code uses hex constants to generate a particular value, you might need to modify your code for use on 64-bit Intel architecture, because the value might change.

For example, the value of 0xFFFFFFFF on 32-bit Intel architecture is -1, but the value on 64-bit Intel architecture is 4,294,967,295. The value of 0x100000000 on 32-bit Intel architecture is 0, but the value on 64-bit Intel architecture is 4,294,967,296.


Solution

Evaluate your code for hex constants and replace them with a C const declaration, such as the following:

const int all1s= 0xFFFFFFFF; 

In addition, be sure to specify a particular data type, including whether it is signed or unsigned, and use type suffixes as appropriate, such as L or UL.

Related information about migrating other types of constants from 32-bit Intel architecture to 64-bit Intel architecture is covered in the following separate items:

 


Source

Preparing Code for the IA-64 Architecture (Code Clean)