public void Foo(double d){
// when called below, d == 2^32-1
...
}
public void Bar(){
uint ui = 1;
Foo( 0 - ui );
}
I would expect both 0 and ui to be promoted to signed longs here.
True, with the 0 literal it is knowable at compile time that a cast to uint is safe,
but I suppose this all just seems wrong. At least a warning should be issued.
Thanks!
Does the language spec cover a semi-ambiguous case like this?
It’s the
intthat is being cast touintto perform substraction from 0 (which is implicitly interpreted by the compiler asuint). Note thatinttouintis an implicit conversion hence no warning. There is nothing wrong with your code… except thatuintis not CLS-compilant. You can read why here. More info on CLS-compilant code on MSDN