title: Alternatives to type casting when formatting NS(U)Integer on 32 and 64 bit architectures?
body: <p>With the 64 bit version of iOS we can't use <code>%d</code> and <code>%u</code> anymore to format <code>NSInteger</code> and <code>NSUInteger</code>. Because for 64 bit those are typedef'd to <code>long</code> and <code>unsigned long</code> instead of <code>int</code> and <code>unsigned int</code>.</p>
  
  <p>So Xcode will throw warnings if you try to format NSInteger with %d. Xcode is nice to us and offers an replacement for those two cases, which consists of a l-prefixed format specifier and a typecast to long. Then our code basically looks like this:</p>
  
  <pre><code>NSLog(@"%ld", (long)i);
  NSLog(@"%lu", (unsigned long)u);
  </code></pre>
  
  <p>Which, if you ask me, is a pain in the eye. </p>
  
  <p>A couple of days ago someone at Twitter mentioned the format specifiers <code>%zd</code> to format signed variables and <code>%tu</code> to format unsigned variables on 32 and 64 bit plattforms. </p>
  
  <pre><code>NSLog(@"%zd", i);
  NSLog(@"%tu", u);
  </code></pre>
  
  <p>Which seems to work. And which I like more than typecasting. </p>
  
  <p>But I honestly have no idea why those work. Right now both are basically magic values for me.  </p>
  
  <p>I did a bit of research and figured out that the <code>z</code> prefix means that the following format specifier has the same size as <code>size_t</code>. But I have absolutely no idea what the prefix <code>t</code> means. So I have two questions:</p>
  
  <p>What exactly do <code>%zd</code> and <code>%tu</code> mean?</p>
  
  <p>And is it safe to use <code>%zd</code> and <code>%tu</code> instead of Apples suggestion to typecast to long?</p>
  
  <hr>
  
  <p><em>I am aware of similar questions and Apples 64-Bit Transition guides, which all recommend the <code>%lu (unsigned long)</code> approach. I am asking for an alternative to type casting.</em> </p>