Sun Studio 12: C User's Guide

7.3.2 Integer and Long Size Change

Because integers and longs are never really distinguished in the ILP32 data-type model, your existing code probably uses them indiscriminately. Modify any code that uses integers and longs interchangeably so it conforms to the requirements of both the ILP32 and LP64 data-type models. While an integer and a long are both 32-bits in the ILP32 data-type model, a long is 64 bits in the LP64 data-type model.

Consider the following example:


int waiting;
long w_io;
long w_swap;
...
waiting = w_io + w_swap;

%
warning: assignment of 64-bit integer to 32-bit integer

Furthermore, large arrays of integers, such as longs or unsigned longs, can cause serious performance degradation in the LP64 data-type model as compared to arrays of ints or unsigned ints. Large arrays of longs or unsigned longs can also cause significantly more cache misses and consume more memory.

Therefore, if int works just as well as long for the application purposes, it’s better to use int rather than long.

This is also an argument for using arrays of ints instead of arrays of pointers. Some C applications suffer from serious performance degradation after conversion to the LP64 data-type model because they rely on many, large, arrays of pointers.