Compare int and unsigned int

前端 未结 2 819
逝去的感伤
逝去的感伤 2020-12-17 20:51

If one needs to compare int x with unsigned int y which is safer/better/nicer in C99 and with gcc 4.4+:

2条回答
  •  既然无缘
    2020-12-17 21:30

    Safest is to check that the number is in range before casting:

    if (x >= 0 && ((unsigned int)x) == y)
    

提交回复
热议问题