unsigned to signed conversion
<p>Consider the following:</p>

<pre><code>#include &lt;iostream&gt;

int main() {

    unsigned int x = 3;
    unsigned int y = 5;

    std::cout &lt;&lt; "a: " &lt;&lt; x - y        &lt;&lt; std::endl;

    std::cout &lt;&lt; "b: " &lt;&lt; ((int)x) - y &lt;&lt; std::endl;

    std::cout &lt;&lt; "c: " &lt;&lt; x - ((int)y) &lt;&lt; std::endl;

    std::cout &lt;&lt; "d: " &lt;&lt; ((int)x) - ((int)y) &lt;&lt; std::endl;

}

$ g++ -Wconversion -Wall uint_stackoverflow.cc -o uint_stackoverflow &amp;&amp; ./uint_stackoverflow
a: 4294967294
b: 4294967294
c: 4294967294
d: -2
</code></pre>

<p>I understand why "a" doesn't give the expected result. But why "b" and "c" fail puzzles me. For "b" I thought after casting "x" to "int" the result will be "int" again.</p>

<p>Could you please enlighten me?</p>

<p>edit: Shouldn't the compiler warn? g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5</p>

<p>Thanks,</p>

<p>Somebody</p>
