size_t + ptrdiff_t

Juan Manuel Cabo juanmanuel.cabo at gmail.com
Tue Feb 21 17:31:42 PST 2012


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.

THis is already nitpicky. I'm sorry for the noise.

--jm





More information about the Digitalmars-d mailing list