In many 64-bit OSes (such as 64-bit Linux), ints are still only 32 bits wide; only longs and pointers are 64 bits wide. This is referred to as an LP64 data model. The reason for this is that in many cases, an int does not need more range than is provided by 32 bits, and using 64 bits would only waste memory. Under 64-bit Windows, evens longs are 32-bit (for compatibility with 32-bit Windows), and only long longs are 64-bit; this is referred to as an LLP64 data model.
If your application is going to be running on 32-bit as well as 64-bit operating systems, then the range of a 32-bit integer is obviously sufficient -- otherwise, you would be in trouble on the 32-bit OS. So just go ahead and use ints in those cases. If you can identify cases where you need the range of a 64-bit integer, use an int64_t
(defined in stdint.h
) explicitly. To make sure the binary data formats you write to disk are compatible across platforms, use int32_t
and int64_t
explicitly in those places... but also be aware of potential endianness issues.
Finally, when writing 64-bit code, be aware that pointers cannot be converted to ints in a LP64 data model -- so use uintptr_t
instead.
If you code cleanly, 32-bit/64-bit portability should be almost a non-issue -- there's not really much more you need to be aware of than what I've written above. Portability between Windows and Linux will generate much greater issues that portability between 32-bit and 64-bit.