i will always be >=0 because it is declared as unsigned and therefore interpreted as an unsigned integer. So your first test will always be false.
Your call to foo(bar) actually convert int to unsigned int . Perhaps this confuses you. And the "conversion" does not actually change the value of the bytes / bits of your whole, it is just a matter of formal typing and interpretation.
See this answer for examples of signed / unsigned conversions.
Here is a simple example (the exact output depends on the number of bytes of unsigned int in your system, for me it is 4 bytes).
the code:
printf("%u\n", (unsigned int) -2);
Conclusion:
4294967294
wap26 source share