<div class="gmail_quote">On 22 February 2012 03:31, Juan Manuel Cabo <span dir="ltr"><<a href="mailto:juanmanuel.cabo@gmail.com">juanmanuel.cabo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 02/21/2012 10:13 PM, Sean Kelly wrote:<br>
> I think this is actually a good thing, since working with unsigned integers is a pain.<br>
<br>
</div>Yes, I would prefer that msb bit to be the sign too, but behavior might depend on it,<br>
and correctness and predictability is important.<br>
<br>
My first code snippet was WRONG (sorry for the noise). And I couldn't even<br>
reproduce the problem with my VC.<br>
<br>
A correct snippet is simply this:<br>
<br>
    size_t s = -2;<br>
<br>
    if (s > 0) {<br>
         printf("unsigned");<br>
    } else {<br>
         printf("signed");<br>
    }<br>
<br>
Also, the shift operator is does a logical or arithmetic shift depending<br>
on whether it is signed or unsigned, so the result is different<br>
if you do<br>
     s >> 1<br>
whether s is signed or unsigned.<br></blockquote><div><br></div><div>Actually, it doesn't.</div><div>It is not defined by C whether it should be arithmetic or logical shift right, and it is up to the compiler to choose.</div>
<div>Microsoft's PPC compiler produces a *logical* signed shift right for instance.</div><div><br></div></div>