title: What is the correct type for array indexes in C?
body: <p>What type for array index in C99 should be used? It have to work on LP32, ILP32, ILP64, LP64, LLP64 and more. It doesn't have to be a C89 type.</p>
  
  <p>I have found 5 candidates:</p>
  
  <ul>
  <li><code>size_t</code></li>
  <li><code>ptrdiff_t</code></li>
  <li><code>intptr_t</code> / <code>uintptr_t</code></li>
  <li><code>int_fast*_t</code> / <code>uint_fast*_t</code></li>
  <li><code>int_least*_t</code> / <code>uint_least*_t</code></li>
  </ul>
  
  <p>There is simple code to better illustrate problem. What is the best type for <code>i</code> and <code>j</code> in these two particular loops. If there is a good reason, two different types are fine too.</p>
  
  <pre><code>for (i=0; i&lt;imax; i++) {
          do_something(a[i]);
  }
  /* jmin can be less than 0 */
  for (j=jmin; j&lt;jmax; j++) {
          do_something(a[j]);
  }
  </code></pre>
  
  <p>P.S.
  In the first version of question I had forgotten about negative indexes.</p>
  
  <p>P.P.S.
  I am not going to write a C99 compiler. However any answer from a compiler programmer would be very valuable for me.</p>
  
  <p>Similar question:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/1464174/size-t-vs-intptr-t">size_t vs. uintptr_t</a><br>
  The context of this question if different though.</li>
  </ul>