From 293185e71e33274610e8b5801f7f41ff0c620edd Mon Sep 17 00:00:00 2001
From: Rob Landley
Toybox should work on both 32 bit and 64 bit systems. 64 bit desktop -hardware went mainstream in 2005 and was essentially ubiquitous -by the end of the decade, but 32 bit hardware will continue to be important -in embedded devices for several more years.
- -Toybox relies on the fact that on any Unix-like platform, pointer and long -are always the same size (on both 32 and 64 bit). Pointer and int are _not_ -the same size on 64 bit systems, but pointer and long are. -This is guaranteed by the LP64 memory model, a Unix standard (which Linux -and MacOS X both implement, and which modern 64 bit processors such as -x86-64 were designed for).
- -Back -before unix.org went down, they hosted the -LP64 standard and -the LP64 rationale, but the important part is -LP64 gives all the basic C integer types defined sizes:
+hardware went mainstream in in 2005 +and was essentially ubiquitous by 2012, +but 32 bit hardware will continue to be important in embedded devices for years to come. + +Toybox relies on the +LP64 standard +which Linux, MacOS X, and BSD all implement, and which modern 64 bit processors such as +x86-64 were explicitly designed to +support. (Here's the original LP64 white paper.)
+ +LP64 defines explicit sizes for all the basic C integer types, and +guarantees that on any Unix-like platform "long" and "pointer" types +are always the same size. This means it's safe to assign pointers into +longs and vice versa without losing data: on 32 bit systems both are 32 bit, +on 64 bit systems both are 64 bit.
C type | 32 bit sizeof | 64 bit sizeof |
long long | 8 bytes | 8 bytes |
Note that Windows doesn't work like this, and I don't care. -The -insane legacy reasons why this is broken on Windows are explained here.
+LP64 eliminates the need to use c99 "uint32_t" and friends: the basic +C types all have known size/behavior, and the only type whose +size varies is "long", which is the natural register size of the processor.
+ +(Note that Windows doesn't work like this, and I don't care, but if you're +curious here are The insane legacy reasons why this is broken on Windows are explained here.
On platforms like x86, variables of type char default to unsigned. On -- cgit v1.2.3