I am trying to cause an implicit type conversion between an int
and unsigned int
in some code that I wrote. The compiler gives an unexpected result.
According to the rules for implicit conversion between signed and unsigned integers (of equal rank), the code should produce a large positive number as its output.
unsigned int q = 90;
int w = -1;
printf("q+w=%u\n", q + w);
As the output to this program, which you can view here, the result is 89. I would expect the int w
to be coerced to the type unsigned int
before arithmetic occurs, however, and produce the expected result.