Why is this function call ambiguous?

It has little to do with rank of the type defined in 4.13. 4.13 defined internal rankings used to describe integral promotions and usual arithmetic conversions. They by itself do not directly affect overload resolution. Rankings relevant to overload resolution are defined in “13.3.3.1.1 Standard conversion sequences” and then used in “13.3.3.2 Ranking implicit conversion … Read more

Does one double promote every int in the equation to double?

I purposefully did not compile and run then on my system, since this is the type of thing that could be compiler dependent. This is not compiler dependent. C++ clearly defines the order of these operations and how they are converted. How the conversion happens is dependent on the order of operations. double result1 = … Read more

Why is ‘char -> int’ promotion, but ‘char -> short’ is conversion (but not promotion)?

Historical motivation: C The idea of integral promotions dates all the way back to pre-standard C. When providing arguments to variadic functions (…) or to functions without a prototype, promotions are applied. I.e. calling: // function declaration with no prototype void mystery(); // … char c=”c”; mystery(c); // this promotes c to int // in … Read more

Why does it make a difference if left and right shift are used together in one expression or not?

This little test is actually more subtle than it looks as the behavior is implementation defined: unsigned char x = 255; no ambiguity here, x is an unsigned char with value 255, type unsigned char is guaranteed to have enough range to store 255. printf(“%x\n”, x); This produces ff on standard output but it would … Read more

Why must a short be converted to an int before arithmetic operations in C and C++?

If we look at the Rationale for International Standard—Programming Languages—C in section 6.3.1.8 Usual arithmetic conversions it says (emphasis mine going forward): The rules in the Standard for these conversions are slight modifications of those in K&R: the modifications accommodate the added types and the value preserving rules. Explicit license was added to perform calculations … Read more