A
Andy
Hello All,
I have an overflow problem regarding INT_MIN. When I print out
INT_MIN-1, it equals to 2147483647, which is greater than 0. But when
I compare it with 0, like (INT_MIN-1)>0. gcc just gives 0 value, is
2147483647 supposed to be bigger than 0? I am confused. For testing
purpose, my code is as follows:
#include <stdio.h>
#include <limits.h>
int main(){
int i = INT_MIN;
int j = i-1;
int cmp = ((i-1)>0);
printf("j=%d, cmp=%d", j, cmp);
return 0;
}
$ j=2147483647, cmp=0
Thanks for help me out...
~Andy W.
I have an overflow problem regarding INT_MIN. When I print out
INT_MIN-1, it equals to 2147483647, which is greater than 0. But when
I compare it with 0, like (INT_MIN-1)>0. gcc just gives 0 value, is
2147483647 supposed to be bigger than 0? I am confused. For testing
purpose, my code is as follows:
#include <stdio.h>
#include <limits.h>
int main(){
int i = INT_MIN;
int j = i-1;
int cmp = ((i-1)>0);
printf("j=%d, cmp=%d", j, cmp);
return 0;
}
$ j=2147483647, cmp=0
Thanks for help me out...
~Andy W.