I have run into a couple of similar quirks regarding uint usage in both C++ and C#, and now I'm wondering on the reasoning (which may be completely different for each example). For both of these examples, note that I am compiling with the warning levels set to maximum.
(1) gcc complains about comparing an int to a uint in the following, whereas vc++ does not:
uint foo = <somevalue>;
if( foo == ~0 ) //right here
...
Comparing to 0 is just fine without any casting on both gcc and vc++.
(2) In C# 3.5, I just ran into a similiar issue. The following works fine:
uint foo = 1;
uint bar = 2;
But this gives a uint/int warning:
bool condition = <somevalue>;
uint foo = condition ? 1 : 2; //right here
What gives, why is the compiler so sensitive about signed-ness of immediate values? I completely understand the issue when assigning from variables, but this just doesn't make sense to me for immediate values; is there some hidden difficulty in the parsing that prevents this behavior from being allowed? Or what?
Edit: Yes, I know I can suffix my numbers with 'u', but that sidesteps my question, which is about implicitly casting to the left-hand-side, not explicitly casting the right-hand-side.