title: Casting negative integer to larger unsigned integer
body: <p>I've encountered code that performs the following conversion:</p>
  
  <p><code>static_cast&lt;unsigned long&gt;(-1)</code></p>
  
  <p>As far as I can tell, the C++ standard defines what happens when converting a signed integer value to an unsigned integral type (see: <a href="https://stackoverflow.com/questions/2711522/what-happens-if-i-assign-a-negative-value-to-an-unsigned-variable">What happens if I assign a negative value to an unsigned variable?</a>).</p>
  
  <p>The concern I have in the above code is that the source and destination types may be different sizes and whether or not this has an impact on the result. Would the compiler enlarge the source value type before casting? Would it instead cast to an unsigned integer of the same size and then enlarge that? Or perhaps something else?</p>
  
  <p>To clarify with code,</p>
  
  <pre><code>int nInt = -1;
  long nLong = -1; // assume sizeof(long) &gt; sizeof(int)
  
  unsigned long res1 = static_cast&lt;unsigned long&gt;(nInt)
  unsigned long res2 = static_cast&lt;unsigned long&gt;(nLong);
  
  assert(res1 == res2); // ???
  </code></pre>
  
  <p>Basically, should I be worrying about writing code like</p>
  
  <pre><code>static_cast&lt;unsigned long&gt;(-1L)
  </code></pre>
  
  <p>over</p>
  
  <pre><code>static_cast&lt;unsigned long&gt;(-1)
  </code></pre>