First of all, the value produced by sizeof
is of size_t
which is unsigned
type. NOTE
As the unsigned
type is of higher rank than the signed
type, while performing the comparison, as per the norms of the relation operator, the usual arithmetic conversions are performed, meaning the signed type is promoted to unsigned type.
In your case, the -1
, when considered as unsigned
, represent the highest possible unsigned
value, thus, no wonder
if (sizeof(int) > -1)
Evaluates to false.
Moral of the story: Attempted comparison between a signed
and an unsigned
is expected to produce weird result, just as in your case. You should enable compiler warning and try to solve the issues reported by the compiler.
NOTE:
From C11
, chapter §7.19, <stddef.h>
,
size_t
which is the unsigned
integer type of the result of the sizeof
operator.