I wonder if it’s a good idea to keep using int (which is 32 bit on both x86 and x86_64) on 64 bit programs for variables that have nothing special and do not really need to span up to 2^64, like iteration counters, or if it’s better to use size_t which matches the word size of the CPU.
For sure if you keep using int you save half of the memory, and that could mean something speaking about CPU cache, but I don’t know then if on 64 bit machine every 32 bit number has to be extended to 64 bit before any use.
EDIT:
I’ve ran some test with a program of mine (see the self answer, I still keep janneb’s as accepted though because it is good). It turns out that there is a significant performance improvement.
For array indices and pointer arithmetic, types which are of the same size as a pointer (typically, size_t and ptrdiff_t) can be better, as they avoid the need to zero or sign extend the register. Consider
With GCC 4.4 -O2 on x86_64 the following asm is generated:
As can be seen, the versions with the int and unsigned int index (onei and oneu) requires an extra instruction (movslq/mov) to sign/zero extend the register.
As was mentioned in a comment, the downside is that encoding a 64-bit register takes more space than the 32-bit part, bloating the code size. Secondly, ptrdiff_t/size_t variables need more memory than the equivalent int; if you have such arrays it can certainly affect performance much more than the relatively small benefit of avoiding the zero/sign extension. If unsure, profile!