3 ms·
> There seems no sensible reason why ints are 32 bit on a 64 bit platform, it only introduces inefficiency[1] I don't think that is a fair summary of your link
by haberman 10y ago
> There seems no sensible reason why ints are 32 bit on a 64 bit platform, it only introduces inefficiency[1]
I don't think that is a fair summary of your link at all.
First of all, the conclusion of that link's analysis is that there is no performance penalty in this case, because the compiler exploits undefined behavior to eliminate any penalty it might otherwise have caused.
Secondly, 32-bit instructions on x64 are smaller than 64-bit instructions. For example "inc eax" is a 2-byte instruction, but "inc rax" is 3 bytes. This is because 64-bit instructions need a REX prefix.
Also, as others have mentioned, there is the issue of RAM usage.
I'm not arguing that 32-bit integers are superior overall. I'm just saying that 64-bit integers aren't strictly better in terms of efficiency. For cases that will never need more than 32 bits, a 32-bit integer is probably better.