Let say I have a 32-bit machine.
I know during integer promotion the expressions are converted to:\\
int
if all
The integer promotion rule, correctly cited C11 6.3.1.1:
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 anint
; otherwise, it is converted to anunsigned int
. These are called the integer promotions. All other types are unchanged by the integer promotions.
Where "otherwise, it is converted to an unsigned int" is in practice only used in one particular special case, namely where the smaller integer type unsigned short
has the same size as unsigned int
. In that case it will remain unsigned.
Apart from that special case, all small integer types will always get promoted to (signed) int
regardless of their signedness.
Assuming 32 bit int
, then:
x = (speed*pt)/length;
speed
is signed 32, it will not get promoted. ptr
will get integer promoted to int
(signed 32). The result of speed*ptr
will have type int
.
length
will get integer promoted to int
. The division will get carried out with operands of type int
and the resulting type will be int
.
The result will get converted to signed 16 as it is assigned to x
(lvalue conversion during assignment).
x = pt + length;
is similar, here both operands of + will get promoted to int
before addition and the result will afterwards get converted to signed 16.