comparsion bwt sign and unsign

if( -1 < ( unsignd int ) 2 )
{
cout<< "yes" << endl;
}
how compilar compare sign with unsign ?
I think it's undefined, but I'm not entirely sure. It probably varies from compiler to compiler as well.
Last edited on
-1 will be converted to an unsigned int before the comparison take place if I understand the standard correctly.
I'm with Peter87 on this one.

if( -1 < ( unsigned int ) 2 )

Is the same as

if(0xFFFFFFFF < 0x00000002)

or

if(4294967295 < 2)

Andy

P.S. if(-2147483647 < ( unsigned int ) 2) is also false (that's the lowest value that fits in an int)
Last edited on
Topic archived. No new replies allowed.