title: printf(), unsigned char, and %hhd
body: <p>The program:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;limits.h&gt;
  
  int main( void )
  {
  #ifdef __CHAR_UNSIGNED__
      printf( "%d\n", __CHAR_UNSIGNED__ );
  #endif
      printf( "%d\n", CHAR_MAX );
      printf( "%d\n", CHAR_MIN );
      printf( "%hhd\n", CHAR_MAX );
  }
  </code></pre>
  
  <p>Output (on my x86_64 desktop):</p>
  
  <pre><code>127
  -128
  127
  </code></pre>
  
  <p>That is as expected. Now, I ran the same on a Raspberry Pi (ARM):</p>
  
  <pre><code>1
  255
  0
  -1
  </code></pre>
  
  <p>So... <strong>apparently I have misunderstood</strong> some step <code>CHAR_MAX</code> is taking in its way to output, as <strong>the output I was expecting</strong> in that last line -- passing <code>CHAR_MAX</code> to <code>%hhd</code> on a machine with <code>char</code> being unsigned -- <strong>would have been <code>255</code></strong>.</p>
  
  <p>(And if you should ask, the result is the same for <code>(char)CHAR_MAX</code>, and <code>(unsigned char)CHAR_MAX</code>.)</p>
  
  <p>What am I missing?</p>
  
  <p>This happened to me during regression testing my own <code>printf()</code> implementation on the Raspberry Pi -- which, by the way, <em>does</em> print <code>255</code>. So... only one implementation is doing it right, and I have the sinking feeling it's not mine...</p>