Open System Services Programmer's Guide

HP recommends that code be compiled with the migration check warnings enabled, and each
warning examined, before compiling with -Wlp64.
64-Bit Programming Guidelines
When transitioning to 64-bit mode, strive to maintain a single set of source files and header files
for both data models. Consider the following guidelines before porting to 64-bit mode:
Data Truncation – Truncation problems can happen when assignments are made between
64-bit and 32-bit data items. Because int, long, and pointer 32-bit data types are all the
same size in ILP32, mixed assignments between these data types do not present any special
concerns. However, in the LP64 data model, long and pointer data types are no longer the
same size as int. In LP64, truncation occurs when pointer or long are assigned to int.
In LP64, truncation can occur during:
Initialization
Assignments
Parameter passing
Return statements
Casts
To prevent data truncation:
Avoid assigning a long to an int
Avoid storing a pointer in an int
Avoid truncating function return values
Use appropriate print specifiers
Data Type Promotion – When comparisons and arithmetic operations are performed between
variables and constants with different data types, the C compiler first converts these types to
compatible types. For example, when a short is compared to a long, the short is first
converted to a long. This conversion process is called data type promotion.
IMPORTANT: Avoid arithmetic between signed and unsigned numbers
Certain data type promotions result in signed numbers being treated as unsigned numbers.
When this happens, you can occasionally get unexpected results. For example, in ILP32:
long result;
int i = -2;
unsigned int j = 1;
result = i + j;
The ILP32 intermediate result (an unsigned int) and the final result (a signed long) have the
same internal representation because they are both 32 bits. Since the final result is signed,
the answer is -1.
Under the LP64 data model, the results are different. When the 32-bit intermediate result (an
unsigned int) is converted to the 64-bit final result (a signed long), the left 32 bits are
zero-filled. This results in a very large 64-bit positive number.
Pointers – Avoiding pointer corruption is an important concern when migrating to LP64:
Assigning a 32-bit hexadecimal constant or an int to a pointer results in an invalid
address and might cause errors when the pointer is de-referenced.
Casting a pointer to an int results in truncation.
308 64-Bit Support in OSS and Guardian