I have this sample code which generates the following warning (VS2008 compiler with SP1):
warning C4146: unary minus operator
applied to unsigned type, result still
unsigned
Code:
void f(int n)
{
}
int main()
{
unsigned int n1 = 9;
f(-n1);
}
But since function f is taking it’s parameter as an int shouldn’t this code compile without any warnings?
Standard 5.3.1/7
And the paragraph on Integral Promotion 4.5/1
i.e. an unsigned int will not be promoted to an int.