From k&R C
- First, if either operand is long double, the other is converted to long double.
- Otherwise, if either operand is double, the other is converted to double.
- Otherwise, if either operand is float, the other is converted to float.
- Otherwise, the integral promotions are performed on both operands; ...
This would mean below expression
char a,b,c;
c=a+b;
is actually caculated as
c = char((int)a+(int)b);
What is the rationale behind this rule?
Do these conversions happen if a, b and c were short ?
No that's not actually true. C99 Section
5.1.2.3 Program execution
, clause 10 covers exactly the case you ask about:So, if the operation is known to produce the same result, there's no requirement for using the wider values.
But if you want the rationale behind a specific decision made in the standard, you have to look at, ..... wait for it, ..... yes, the Rationale document :-)
In section 6.3.1.8 of that rationale (sections match those in the standard), it states: