title: C++ int vs long long in 64 bit machine
body: <p>My computer has 64 bit processor and when I look for <code>sizeof(int)</code>, <code>sizeof(long)</code>, and <code>sizeof(long long)</code>, it turns out that <strong>int</strong> and <strong>long</strong> are 32 bits, and <strong>long long</strong> is 64 bit. I researched the reason, and it appears that popular assumption telling that <strong>int</strong> in C++ fits machine's word size is wrong. As I understood it is up to compiler to define what will be the size, and mine is Mingw-w64. The reason for my research was understanding that if the usage of types smaller than word size is beneficial for speed(for instance, <strong><em>short</strong> vs <strong>int</em></strong>) or if it has negative effect. In 32 bit system, one popular opinion is: due to the fact that word size is <strong>int</strong>, <strong>short</strong> will be converted into <strong>int</strong> and it would cause additional bit shifts and etc, thus leading to worse performance. Opposing opinion is that there will be benefit in cache level(I didn't go deep into it), and using <strong>short</strong> would be usefull for virtual memory economy. So, in addition to confusion between this dilemma, I also face another problem. My system is 64 bit, and it doesn't matter if I use <strong>int</strong> or <strong>short</strong> , it still will be less than the word size, and I start thinking that wouldn't it be efficient to use 64 bit <strong>long long</strong> because it is at the level the system is designed to. Also I read that there is another constraint, which is library(ILP64, LP64) of OS that defines the type sizes. In ILP64 default <strong>int</strong> is 64 bit in contrast to LP64, would it speed up the program if I use OS with ILP64 support? Once I started to ask which type should I use for speeding up my C++ program,  I faced more deep topics in which I have no expertise and some explanations seems to contradict to each other. Can you please explain:</p>
  
  <p>1) If it is best  practice to use <strong>long long</strong> in x64 for achieving maximum performance even for for 1-4 byte data?</p>
  
  <p>2) Trade-off in using a type less than word size(memory win vs additional operations)</p>
  
  <p>3) Does a x64 computer where word&amp;int size is 64 bits, has possibility of processing a short, using 16 bit word size by using so called backward compatibility? Or it must put the 16bit file into 64 bit file, and the fact that it can be done defines the system as backward compatible. </p>
  
  <p>4) Can we force the compiler to make the <strong>int</strong> 64 bit?</p>
  
  <p>5) How to incorporate ILP64 into PC that uses LP64?</p>
  
  <p>6) What are possible problems of using code adapted to above issues with other compilers, OS's, and architectures(32 bit processor)?</p>