1. Introduction to the C Compiler
2. C-Compiler Implementation-Specific Information
7. Converting Applications for a 64-Bit Environment
7.2 Implementing Single Source Code
Helpful Types Such as unintptr_t
7.3 Converting to the LP64 Data Type Model
7.3.1 Integer and Pointer Size Change
7.3.2 Integer and Long Size Change
7.3.4 Pointer Arithmetic Instead of Integers
7.3.8 Beware of Implicit Declarations
7.3.9 sizeof( ) Is an Unsigned long
7.3.10 Use Casts to Show Your Intentions
7.3.11 Check Format String Conversion Operation
7.4.1 Derived Types That Have Grown in Size
7.4.2 Check for Side Effects of Changes
7.4.3 Check Whether Literal Uses of long Still Make Sense
7.4.4 Use #ifdef for Explicit 32-bit Versus 64-bit Prototypes
7.4.5 Calling Convention Changes
7.5 Checklist for Getting Started
8. cscope: Interactively Examining a C Program
A. Compiler Options Grouped by Functionality
B. C Compiler Options Reference
C. Implementation-Defined ISO/IEC C99 Behavior
E. Implementation-Defined ISO/IEC C90 Behavior
H. The Differences Between K&R Solaris Studio C and Solaris Studio ISO C
The biggest difference between the 32-bit and the 64-bit compilation environments is the change in data-type models.
The C data-type model for 32-bit applications is the ILP32 model, so named because integers, longs, and pointers are 32-bit data types. The LP64 data model, so named because longs and pointers grow to 64-bits, is the creation of a consortium of companies across the industry. The remaining C types, int, long long, short, and char are the same in both data-type models.
Regardless of the data-type model, the standard relationship between C integral types holds true:
sizeof (char) <= sizeof (short) <= sizeof (int) <= sizeof (long)
The following table lists the basic C data types and their corresponding sizes in bits for both the ILP32 and LP64 data models.
Table 7-1 Data Type Size for ILP32 and LP64
|
It is not unusual for current 32-bit applications to assume that integers, pointers, and longs are the same size. Because the size of longs and pointers change in the LP64 data model, you need to be aware that this change alone can cause many ILP32 to LP64 conversion problems.
In addition, it becomes very important to examine declarations and casts; 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 you intend, you need to explicitly declare the types of constants. You can also use casts in expressions to make certain that the expression is evaluated the way you intend. This is particularly true in the case of sign extension, where explicit casting is essential for demonstrating intent.