On 22 February 2012 03:31, Juan Manuel Cabo <juanmanuel.cabo@gmail.com> wrote:
On 02/21/2012 10:13 PM, Sean Kelly wrote:
> I think this is actually a good thing, since working with unsigned integers is a pain.

Yes, I would prefer that msb bit to be the sign too, but behavior might depend on it,
and correctness and predictability is important.

My first code snippet was WRONG (sorry for the noise). And I couldn't even
reproduce the problem with my VC.

A correct snippet is simply this:

   size_t s = -2;

   if (s > 0) {
        printf("unsigned");
   } else {
        printf("signed");
   }

Also, the shift operator is does a logical or arithmetic shift depending
on whether it is signed or unsigned, so the result is different
if you do
    s >> 1
whether s is signed or unsigned.

Actually, it doesn't.
It is not defined by C whether it should be arithmetic or logical shift right, and it is up to the compiler to choose.
Microsoft's PPC compiler produces a *logical* signed shift right for instance.