pub enum DataModel {
IP16,
IP16L32,
LP32,
ILP32,
LLP64,
LP64,
ILP64,
SILP64,
Unknown,
}Expand description
A data model is the choices of bit width of integer types by each platform.
§Examples
use data_models::*;
let model = DataModel::LP64; // e.g. Linux
let p = model.size_of::<Pointer>();
assert_eq!(p, 8);§Background
The C standard defines five base types for integers
- char
- short
- int
- long
- long long
The standard does not specify the exact number of bits for each type. A platform or vendor-dependent data model specifies the exact bit widths.
The names of the models are conventions where the type is signified by a letter and its size; for example, ILP32 would mean (I)nteger, (L)ong, and (P)ointer are 32-bits. Although, make note, the naming scheme is not super consistent.
Four data models found wide acceptance:
-
LP32 or 2/4/4 (int is 16-bit, long and pointer are 32-bit) M68k mac and Win16 API
-
ILP32 or 4/4/4 (int, long, and pointer are 32-bit); Win32 API Unix and Unix-like systems (Linux, Mac OS X)
-
LLP64 or 4/4/8 (int and long are 32-bit, pointer is 64-bit) Win64 API
-
LP64 or 4/8/8 (int is 32-bit, long and pointer are 64-bit) Unix and Unix-like systems (Linux, Mac OS X)
§References
- J. R. Mashey. The long road to 64 bits. ACM Queue Magazine, 4(8):24–35, 1996.
- T. Lauer. Porting to Win32: A Guide to Making Your Applications Ready for the 32-Bit Future of Windows. Springer, 1996.
Variants§
IP16
16-bit integer and pointer (16-bit PDP-11)
IP16L32
16-bit integer and pointer and 32-bit long (32-bit PDP-11)
LP32
16-bit integer, and 32-bit long and pointer (m68k Mac & win16).
ILP32
32-bit integer, long, and pointer (Unix and Unix-like before mid-1990s & win32).
LLP64
32-bit integer, long, and 64-bit pointer (windows after XP).
LP64
32-bit integer, 64-bit long and pointer (Unix/Linux after the 1990s).
ILP64
64-bit integer, long and pointer (SPARC64 from hal/fujitsu I think).
SILP64
64-bit short, integer, long and pointer (UNICOS from Cray).
Unknown
Sentinel value for unknown model.