If one needs to compare int x with unsigned int y which is safer/better/nicer in C99 and with gcc 4.4+:
int x
unsigned int y
C99
gcc 4.4+
(unsigned int)x == y
x == (int)y
Does it matter?
Safest is to check that the number is in range before casting:
if (x >= 0 && ((unsigned int)x) == y)
2.1m questions
2.1m answers
60 comments
57.0k users