Avoid type-mismatch errors due to the use of #define to define constants with the 64-bit Intel® architecture. In the following code, where #define is used for a constant, the compiler cannot check the code for type mismatches:
#define mask 0x37FFC;
Specify a data type and use the ANSI C const to declare constants. This technique will allow the compiler to check for type mismatches. During compilation, if there are any type mismatches between the declaration and implementation, the compiler will warn you.
The following line of code reworks the code given in the Challenge section, using the ANSI const instead of #define:
const int mask = 0x37FFC;
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:
- How to Support Integer-Constant-Type Suffixes on 64-Bit Intel Architecture
- How to Support Hex Constants on 64-Bit Intel Architecture