Are the "usual arithmetic conversions" and the "integer promotions" the same thing? I have read that the "usual arithmetic conversions" are used to make the operands of an expression the same type, while "integer promotions" are used to promote the types smaller than int
to int
, but in MSDN both of these concepts are placed under "usual arithmetic conversions" only.
Asked
Active
Viewed 1,174 times
3

Lightness Races in Orbit
- 378,754
- 76
- 643
- 1,055

John
- 1,049
- 1
- 14
- 34
-
Why are you formatting stuff-that-isn't-code as code?? – Lightness Races in Orbit Jan 25 '15 at 23:42
-
1*Usual arithmetic conversions* can do more than *integer promotions*. For one thing, they may promote floating point values (e.g. `float` to `double`). For another, they may convert a signed value to unsigned type. The full spec is in **[expr]/9** and is pretty long. – Igor Tandetnik Jan 25 '15 at 23:43
-
2Please pick _one_ language. C and C++ are different languages. – Lightness Races in Orbit Jan 25 '15 at 23:44
-
They are different things in both C and C++ :) – M.M Jan 25 '15 at 23:48
-
@IgorTandetnik: It hasn't been in [expr]/9 in almost four years :P – Lightness Races in Orbit Jan 25 '15 at 23:49
1 Answers
7
No.
The usual arithmetic conversions involve integral promotion under certain circumstances, but these are two separate mechanisms:
[C++14: 5/10]:
Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is also the type of the result. This pattern is called the usual arithmetic conversions, which are defined as follows:
- If either operand is of scoped enumeration type (7.2), no conversions are performed; if the other operand does not have the same type, the expression is ill-formed.
- If either operand is of type
long double
, the other shall be converted tolong double
.- Otherwise, if either operand is
double
, the other shall be converted todouble
.- Otherwise, if either operand is
float
, the other shall be converted tofloat
.- Otherwise, the integral promotions (4.5) shall be performed on both operands.61 Then the following rules shall be applied to the promoted operands:
- If both operands have the same type, no further conversion is needed.
- Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the type of lesser integer conversion rank shall be converted to the type of the operand with greater rank.
- Otherwise, if the operand that has unsigned integer type has rank greater than or equal to the rank of the type of the other operand, the operand with signed integer type shall be converted to the type of the operand with unsigned integer type.
- Otherwise, if the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type, the operand with unsigned integer type shall be converted to the type of the operand with signed integer type.
- Otherwise, both operands shall be converted to the unsigned integer type corresponding to the type of the operand with signed integer type.
The wording is much the same in C11.
Note that the integral promotions may also be performed under circumstances that have nothing to do with the usual arithmetic conversions, e.g. the LHS operand of a bit-shift; ultimately, all this is why the two mechanisms have their own distinct names!

Lightness Races in Orbit
- 378,754
- 76
- 643
- 1,055
-
"If both operands have the same type, no further conversion is needed" So if the two operands are of type `short`, they will not be promoted to an `int`? – John Jan 25 '15 at 23:59
-
1@John. That is not what it says. It says *"the integral promotions (4.5) shall be performed on both operands.61 **Then** the following rules shall be applied to the promoted operands: If both operands have the same type, no further conversion is needed."* You're ignoring the effect of the integral promotions. – Lightness Races in Orbit Jan 26 '15 at 00:00
-
In the MSDN article, the "integral conversions" steps shows that the operands will always end up in the same type, I mean isn't "integral conversions" is about making both operands of the same type? (I am assuming that "integral conversions" and "integral promotions" are the same thing). – John Jan 26 '15 at 00:16
-
@John: The text on MSDN is basically the above-quoted C++ standard text, with the phrase "integral promotions" replaced by the non-standard phrase "integral conversions", and with the subsequent steps removed. I have no idea why they did that. – Lightness Races in Orbit Jan 26 '15 at 01:23
-
But the steps on MSDN for "integral promotions" always result in operands of the same type, the final step says "If none of the above conditions are met, both operands are converted to type int". So why in the C++ standard it says "If both operands have the same type, no further conversion is needed", how is it possible for the operands not to have the same type after the "integral promotions" is performed? – John Jan 26 '15 at 01:29
-
examples would improve this answer: an example where one happens but not the other (and vice versa), one where both happen, and the types that come out. – Yakk - Adam Nevraumont Jan 26 '15 at 01:37
-
@John: They probably _do_ have the same type, in that particular example. – Lightness Races in Orbit Jan 26 '15 at 01:46
-
Just to be sure: after the "integral conversions"/ "integral promotions" is performed, is there's a possibility that the operands will still not have the same type? – John Jan 26 '15 at 02:00
-
-
@mafso The two examples you gave will be promoted without a problem: the first will be promoted according to this rule: "If the above two conditions are not met and either operand is of type float, the other operand is converted to type float", and the second according to this rule: "If the above two conditions are not met, and either operand is of type long, the other operand is converted to type long" I want an example where after the "integral promotions" is performed, the operands will still not be in the same type. (the quoted text is from the MSDN article) – John Jan 26 '15 at 03:46
-
@John: Stop quoting the MSDN article! I quoted the _standard_, which is authoritative, and shows that that text is not part of the integral promotions but instead of the _usual arithmetic conversions_. – Lightness Races in Orbit Jan 26 '15 at 12:43
-
This is confusing. One final question: after reading about this subject in multiple places I think that the MSDN article describes correctly how the conversion is performed, but just with different terminology and order of steps. Is that correct? – John Jan 26 '15 at 15:45
-
@John: I haven't studied it too closely but yes I believe so.... note though that the order of steps may matter in some cases (again, I haven't studied these particular steps but it may be that you can rule that out). – Lightness Races in Orbit Jan 26 '15 at 17:28