c - Comparison between intN_t and uintN_t -


this question has answer here:

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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -