The data model determines the correspondence between the basic data type and the data width in C language. The 32-bit model we use is called ILP32, while 64-bit models have three kinds: LP64, LLP64, and ILP64. In a 64-bit model, the pointer must be 64-bit, but the width of int and long is defined differently in different data types. As the following table:
DataType |
LP32 |
ILP32 |
LLP64 |
LP64 |
ILP64 |
Char |
8 |
8 |
8 |
8 |
8 |
Short |
16 |
16 |
16 |
16 |
16 |
Int |
16 |
32 |
32 |
32 |
64 |
Long |
32 |
32 |
32 |
64 |
64 |
Long Long |
64 |
64 |
64 |
64 |
64 |
Pointer |
32 |
32 |
64 |
64 |
64 |
The former DOS is supposed to be LP32; now Windows 32 and Linux 32 are ILP32; in the upcoming 64bits world, the Windows x64 version uses the LLP64 model, LINUX64 uses the LP64 model, When you compile with GCC you can specify that-m32 be compiled according to the ILP32 model.
The pointer size is associated with the machine word length. For compatibility, when writing C code, declare a 32bit integer with int, and declare a 64bit integer with a long long.
According to POSIX, the correct format string for an integral type is:
Sign |
Char |
Short |
Int |
Long |
Long Long |
Signed |
%hhd |
%hd |
%d |
%ld |
%lld |
Unsigned |
%hhu |
%hu |
%u |
%lu |
%llu |
The difference between int and long