Under ILP32, int, long and pointer types
have the same size and can be freely assigned to one another.
Under LP64, all pointer types are 8 bytes in size. Assigning pointers
to
int types and back again can result in a invalid address,
and passing pointers to a function that expects an
int type
will result in truncation. For example, the following statement show
an incorrect assignment.
int i;
int *p;
i = (int)p;
Note: The problem is harder to detect when casts are used.
Although there is no warning message, the problem still exists.
Avoid making any of the following assumptions:
- A pointer type or a C long type can fit into a C integer type.
- A type that is derived from a pointer type can fit into a type
derived from an integer type.
- The number of bits in a C long type object is assumed, especially
when shifting bits or doing bitwise operations.
- A C integer can be passed to an unprototyped long or pointer parameter.
- A function that is not a prototype can return a pointer or long.