#include <stdio.h>
int main(void)
{
printf("%d", sizeof(signed int) > -1);
return 0;
}
the result is 0 (FALSE).
how can it be?
Im using 64bit ubuntu linux so the result should be (4 > -1) => 1 => True.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
sizeof(signed int)has typesize_t, which is an unsigned type. When you make a comparison between a signed and an unsigned value [and the unsigned value’s type is at least as large as the signed value’s type], the signed value is converted to unsigned before the comparison. This conversion causes-1to become the largest possible value of the unsigned type. In other words, it is as if you wroteYou can make gcc warn when you make this mistake, but it’s not on by default or even in
-Wall: you need-Wextraor more specifically-Wsign-compare. (This warning can produce a great many false positives, but I think it’s useful to turn on for new code.)