My computer thinks that signed int is smaller then -1?
c, casting, linux, unix
Solution
`sizeof(signed int)` has type `size_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 `-1` to become the largest possible value of the unsigned type. In other words, it is as if you wrote
#include <limits.h>
/* ... */
printf("%d", sizeof(signed int) > SIZE_MAX);
You can make gcc warn when you make this mistake, but it's not on by default or even in `-Wall`: you need `-Wextra` or 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.)
Problem
``` #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.