When I'm 64
64-bit architectures offer several advantages:
- Large file support: a large file is one that contains 2GB of data or more.
- 64-bit addressing: a 64-bit process has a virtual address space of 16 exabytes; that's about four billion times larger than the current upper limit of 4GB.
- Breaking the 4GB RAM barrier: on 64-bit systems, the theoretical upper limit of physical RAM is 16 exabytes.
Author's Note: The memory units used in 64-bit environments are:
- 1 terabyte = 1024 gigabyte
- 1 petabyte = 1024 terabytes = 1048576 gigabytes
- 1 exabyte = 1024 petabytes = 1048576 terabytes=1,073,741,824 gigabytes
|
To benefit from these advantages (and others) you must recompile and relink the original source files using a 64-bit compiler and 64-bit libraries, respectively. The good news is that existing 32-bit executables will still run on a 64-bit kernel. The converse isn't true; 64-bit binaries will only run on a 64-bit kernel.
ILP32 Versus LP64
The problems associated with writing 64-bit compliant programs stem from the different datatype models of 32-bit and 64-bit systems. Under the 32-bit datatype model known as ILP32, int, long, and pointers all have the same size of 32-bits. Under the 64-bit datatype model which is called LP64, int still occupies 32-bits, whereas long and pointers occupy 64-bits. The following table summarizes the differences between the two models with respect to the number of bits in each fundamental type:
|
C/C++ native type
|
ILP32
|
LP64
|
|
char
|
8
|
8
|
|
bool
|
usually the same as char
|
usually the same as char
|
|
short
|
16
|
16
|
|
int
|
32
|
32
|
|
long
|
32
|
64
|
|
long long
|
64
|
64
|
|
pointers (of data and
functions)
|
32
|
64
|
|
enum
|
32
|
32
|
|
float
|
32
|
32
|
|
double
|
64
|
64
|
|
long double
|
64/80/128
|
128
|
Platform-independent Datatype Widths
When writing dually-targeted code, it is important to clearly define which objects should have a fixed width, regardless of the target architecture. Fixed-width datatypes may be required in the following cases:
- Reading data from a network connection
- On-disk data that was written by a 32-bit application
- Interfacing with certain binary standards
For such fixed-width datatypes, use the standard
typedefs defined in
<inttypes.h>:
int8_t int16_t int32_t int64_t //signed
uint8_t uint16_t uint32_t uint64_t //unsigned
Strictly speaking,
<inttypes.h> is a
C99 header. However, most C++ compilers nowadays support it.