Wasn't Int type supposed to be the size of the platform word size?

c

Solution

This was true in the olden days, back when the memory bus size had the same width as the processor register size. But that stopped being true a while ago already, the Pentium was the first processor you'd find on standard hardware where the memory bus size got bigger, 64-bits for a 32-bit processor. A simple way to improve the bus throughput.

Memory is a very significant bottle-neck, it is much slower than the execution core of the processor. A problem related to distance, the further an electric signal has to travel, the more difficult it gets to switch the signal at a high frequency without the signal getting corrupted.

Accordingly, the sizes of the processor caches, as well as the efficiency with which the program can use them, heavily determines the program execution speed. A cache miss can easily cost a fat hundred cpu cycles.

Your 64-bit processor did not get double the cache size, L1 is still 32KB instruction and 32KB data whether your program executes in 32-bit or 64-bit mode. The available space on the chip, and most importantly, the distance between the cache and the execution engine are physical constraints, determined by the feature size of the process technology.

So making an int 64-bits, while very simple to do by the compiler, it very detrimental to program speed. Such a program uses the caches much less effectively and will suffer from many more stalls while waiting for the memory bus.

Dominant data models for 64-bit are LLP64, the choice made by Microsoft, and LP64, the choice made on *nix operating systems. Both use 32-bits for int, LLP64 uses 32-bit for long, LP64 makes it 64-bits. A long long is 64-bits on both.

Problem

I've heard many conflicting information on the subject, but in general what I heard that the Int type was supposed to be related to the platform word size, so for example in a 32bit-machine Int has 4 bytes. Except when I started coding in my childhood on DOS, I think my compiler already used 32bit Int even if the target was a 16-bit processor (like the 286) requiring constant use of shorts... And today I compiled a program of mine as 64bit just for kicks, and the Int still ended being 32bit (and short 16bit, I don't tested long). I know the C standard defines this: `short <= int <= long` yet I am curious, what happened? Why everyone decided to use some arbitrary sizes for int?

Original source