Sun WorkShop Compiler C 5.0 User's Guide

Overview of the Data Model Differences

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.

 C Data Type ILP32 LP64
 char 8 8
 short 16 16
 int 32 32
 long3264
 long long 64 64
 pointer3264
 enum 32 32
 float 32 32
 double 64 64
 long double 128 128

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.