Possible duplicate:
unsigned int and signed char comparison
int j = 10;
unsigned int i = 10;
if( j > -1 )
printf("1\n");
else
printf("2\n");
if( i > -1 )
printf("3\n");
else
printf("4\n");
Conclusion:
1
4
I followed in the assembly, and the comparison is similar:
cmp dword ptr [ebp-10h],0FFFFFFFFh
...
cmp dword ptr [ebp-14h],0FFFFFFFFh
But still I don’t understand why one is true and the other is false.
IMO CPU has no idea whether it is signed dword ptror not.
So how does it work under the hood?
UPDATE
can anyone explain this at the assembly level?
source
share