As stated previously, the biggest difference between the 32-bit and 64-bit environments is the change in data-type models.
The C data-type model used for 32-bit applications is the ILP32 model, so named because ints
, longs
, and pointers are 32-bit. The LP64 data model is the C data-type model for 64-bit applications. This model was agreed upon by a consortium of companies across the industry. It is so named because longs and pointers grow to 64-bit quantities. The remaining C types int
, short
, and char
are the same as in the ILP32 model.
The standard relationship between C integral types still holds true.
sizeof (char) <= sizeof (short) <= sizeof (int) <= sizeof (long)
Table 4-1 lists the basic C types, and their corresponding sizes in bits for both the ILP32 and LP64 data type models.
Table 4-1 Data Type Sizes in Bits
C data type |
ILP32 |
LP64 |
---|---|---|
|
8 |
unchanged |
|
16 |
unchanged |
|
32 |
unchanged |
|
32 |
64 |
|
64 |
unchanged |
|
32 |
64 |
|
32 |
unchanged |
|
32 |
unchanged |
|
64 |
unchanged |
|
128 |
unchanged |
It is not unusual for current 32-bit applications to assume that int
s, pointers, and long
s are the same size. Because the size of long
s and pointers change in the LP64 data model, you need to be aware that this change alone can cause many 32-bit to 64-bit conversion problems.
In addition, declarations and casts become very important in showing what is intended; how expressions are evaluated can be affected when the types change. The effects of standard C conversion rules are influenced by the change in data-type sizes. To adequately show what is intended, you might need to declare the types of constants. Casts might also be needed in expressions to make certain that the expression is evaluated the way you intended. This is particularly true in the case of sign extension, where explicit casting might be essential to show intent.
Other problems arise with built-in C operators, format strings, assembly language, and compatibility and interoperability.
The rest of this chapter advises you how to overcome these problems by:
Explaining the problems outlined above in more detail
Describing some of the derived types and include files that are useful to make code safe for both 32-bit and 64-bit
Describing the tools available for helping to make code 64-bit safe
Providing general rules for making code portable between the 32-bit and 64-bit environments