Question about first code: Has an integer promotion been made? I mean, y-->Promotion to int -->conversion to Double ? or y--> conversion to Double? which one is true?
No, there is no integer promotion. For binary +, C 2018 6.5.6 4 says “If both operands have arithmetic type, the usual arithmetic conversions are performed on them.” The usual arithmetic conversions are specified in 6.3.1.8 1. For adding a double and a short, we only need to consider the first two rules:
First, if the corresponding real type of either operand is long double, the other operand is converted, without change of type domain, to a type whose corresponding real type is long double.
Otherwise, if the corresponding real type of either operand is double, the other operand is converted, without change of type domain, to a type whose corresponding real type is double.
So the short is converted to double. The remaining rules in the list begin with “Otherwise” and hence do not apply.
(The type domain refers to real or complex and does not concern us here.)
Question about second code: Has an integer promotion been made? I mean, x and y-->Promotion to int?
Yes, there is an integer promotion. For adding a short and a short, we consider further rules:
Otherwise, if the corresponding real type of either operand is float, the other operand is converted, without change of type domain, to a type whose corresponding real type is float.
Otherwise, the integer promotions are performed on both operands. Then the following rules are applied to the promoted operands:…
Thus, the integer promotions are performed on both operands. This converts them both to int, per 6.3.1.1 2:
If an int can represent all values of the original type (as restricted by the width, for a bit-field), the value is converted to an int; otherwise, it is converted to an unsigned int.
"Promotions are never done when both operands are the same type."-- I believe that this statement is incorrect. In the link to the ISO C11 standard posted by someone else, the standard states:"Otherwise, the integer promotions are performed on both operands."In this sentence, "otherwise" means that if neither of the operands is a floating-point type.