title: Type of an expression
body: <p>Consider the following part of a C++ program; the values printed to the console are given as comments.</p>
  
  <pre><code>{ // case 1
  unsigned int x = 10; 
  unsigned int y = 20; 
  std::cout &lt;&lt; "u/u x - y: " &lt;&lt; x-y &lt;&lt; std::endl; // 4294967286
  }   
  
  { // case 2
  int x = 10; 
  int y = 20; 
  std::cout &lt;&lt; "s/s x - y: " &lt;&lt; x-y &lt;&lt; std::endl; // -10
  }   
  
  { // case 3
  unsigned int x = 10; 
  int y = 20; 
  std::cout &lt;&lt; "u/s x - y: " &lt;&lt; x-y &lt;&lt; std::endl; // 4294967286
  }   
  
  { // case 4
  int x = 10; 
  unsigned int y = 20; 
  std::cout &lt;&lt; "s/u x - y: " &lt;&lt; x-y &lt;&lt; std::endl; // 4294967286
  }
  </code></pre>
  
  <p>I'm trying to figure out how C++ (tried with gcc 4.7.2) defines the type (more specifically, its signedness) from an expression. For cases 1, 3, and 4, the usual arithmetic conversions should promote both values to an unsigned int:</p>
  
  <pre><code> 10 = b00000000000000000000000000001010
   20 = b00000000000000000000000000010100
  </code></pre>
  
  <p>Then, it would do a 2's complement to get -20 and add it:</p>
  
  <pre><code> 10 = b00000000000000000000000000001010
  -20 = b11111111111111111111111111101100
        b11111111111111111111111111110110
  </code></pre>
  
  <p>Interpret that as an <strong>unsigned</strong> integer, and you get 4294967286 -- very well.</p>
  
  <p>Obviously, you get the same calculation/result for case 2; however, the usual arithmetic conversions should result in both operands being interpreted as a signed int, and also the result seems to be interpreted as a <strong>signed</strong> integer.</p>
  
  <p>From this, I'm deducing, that, if the operands are signed after the usual arithmetic conversions, the result is signed. Otherwise, the result is unsigned.</p>
  
  <p>So, my questions are:</p>
  
  <ol>
  <li>Is my deduction correct?</li>
  <li>Where does the standard define this? I cannot find any reference to this in the C or C++ standard.</li>
  <li>What about other operations? I suspect that <code>+</code>, <code>*</code>, etc. will work the same way, but what about shift and logical operations?</li>
  </ol>
  
  <p><strong>Edit:</strong> This seems related to <a href="https://stackoverflow.com/questions/15314778/c11-type-of-signed-unsigned?rq=1">C++11 type of (signed + unsigned)?</a>, but the crucial part for my question seems to be missing from the accepted answer there: will the result of an expression always be the type of both operands after the usual arithmetic conversions?</p>