c - Comparison between intN_t and uintN_t -
this question has answer here:
- signed/unsigned comparisons 4 answers
- why negative int greater unsigned int? 6 answers
i'm puzzled. example:
int x=-1; unsigned y=0; (x<y) ----> false int8_t x=-1; unint8_t y=0; (x<y) ----> true
additionally, compiler raises warnings on first comparison, not second. seems
- (int vs unsigned) - int promoted unsigned
- (intn_t vs uintn_t) - uintn_t promoted intn_t
why have behaviour? like... really?
whenever apply binary arithmetic operator (including comparisons) pair of numeric types both shorter int
, c converts both operands int
before performing operation.
whenever apply binary arithmetic operator pair of numeric types same size, mismatched in signedness, , not shorter int
, c converts signed operand unsigned before operation.
these 2 of "integer promotion" rules. not terribly intuitive, , not 1 if 1 designing c scratch today, , stuck them.
Comments
Post a Comment