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)
1.4m articles
1.4m replys
5 comments
57.0k users