Does my computer think the signed int is less than -1?
3 answers
sizeof(signed int)has a type size_tthat is an unsigned type. When you make a comparison between a signed and unsigned value [and the unsigned value type is at least as large as the signed value type), the sign value is converted to unsigned before the comparison. This conversion leads to what -1becomes the largest possible value of an unsigned type. In other words, it is as if you wrote
#include <limits.h>
/* ... */
printf("%d", sizeof(signed int) > SIZE_MAX);
gcc-, , -Wall: -Wextra , , -Wsign-compare. ( , , .)
+8