by andrewf · 17y ago · 0 comments
// we don't even pretend to work on anything but i386 and LE arm
const unsigned char c[] = { 0x78, 0x56, 0x34, 0x12 };
assert(sizeof(int) == 4 && *((int*)c) == 0x12345678);Except it doesn't even do that well. Traditionally the C "int" type was the largest word size a machine could comfortably work with. But most 64-bit platforms have adopted the "LP64" and "LLP64" conventions - where "int" remains a 32-bit type. One reason to do this is that most values fit comfortably into 32 bits, so a 64-bit "int" wastes memory. Another reason is to keep shoddy code like this running!