title: Comparing 8 bits types of different signedness (int8_t, uint8_t): is result deterministic?
body: <p>I run <a href="http://coliru.stacked-crooked.com/a/d5d2876f81e6e938" rel="nofollow noreferrer">this simple program</a>:</p>
  
  <pre><code>#include &lt;stdint.h&gt;
  #include &lt;iostream&gt;
  int main() {
      uint8_t x = 100;
      int8_t y = -128;
      if (x &lt; y) {
          std::cout &lt;&lt; (int) x &lt;&lt; " is less than " &lt;&lt; (int) y &lt;&lt; std::endl;
      } else {
          std::cout &lt;&lt; (int) y &lt;&lt; " is less than " &lt;&lt; (int) x &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>With output, correctly:</p>
  
  <pre><code>-128 is less than 100
  </code></pre>
  
  <p>I was at first surprised to see no signedness warning was generated.<br/>
  I was then surprised not to have a wrong conversion going on (-128 -> 255) and therefore not getting a wrong result.<br/>
  Then I read <a href="https://stackoverflow.com/a/20192160/2436175">this</a>:</p>
  
  <blockquote>
    <p><sup>1</sup> A prvalue of an integer type other than bool, char16_t, char32_t, or wchar_t whose integer conversion rank (4.13) is less than the rank of int can be converted to a prvalue of type int if int can represent all the values of the source type; otherwise, the source prvalue can be converted to a prvalue of type unsigned int. [§ 4.5]</p>
  </blockquote>
  
  <p><a href="http://www.open-std.org/jtc1/sc22/open/n2356/conv.html" rel="nofollow noreferrer">Link to standard n2356</a><br/>
  What does it mean "<em>Can</em> be converted"? Is it up to the compiler implementation if this conversion will happen and therefore if this expression will return a correct value?</p>
  
  <p>The point is that the compiler <em>shall</em> search for a common type to which convert the 2 operands, but I don't find any obligation in the standard to <em>do its best</em> so that this common type is able to represent all possible values of both the 2 input types.</p>
  
  <p>Note: I tagged also C as this case seems to be also applicable to it.<br/>
  Related question: <a href="https://stackoverflow.com/questions/21027305/comparison-signed-and-unsigned-char">Comparison signed and unsigned char</a>. Also <a href="https://stackoverflow.com/a/25918087/2436175">this</a>.</p>