short a; short b; short x; int c = (int)a + (int)b * (int)x;
Can I refuse a cast (int) in this case? that is, when the compiler performs multiplication and addition, does it work with int intermediate variables or with short intermediate variables?
Edit: what about other types?
int32 a; int32 b; int32 x; int64 c = (int64)a + (int64)b * (int64)x;
Edit 2: It seems to me that
int64 c = a + b*x
may overflow since b * x is computed using int arithmetic. Safer expression:
int64 c = a + (int64)b * (int64)x;
For the case short, ghosts are not needed, since the values ββare shortimplicitly advanced to intin arithmetic terms.
short
int
, , int32 int64 , , , int 64 . , * , :
int32
int64
*
int64 c = a + (int64)b * x;
b int64, x int64, * , , , . a int64 , '+' . , . , c.
b
x
a
c
++ (5.7 )
1 + - . .
, int int.
.
short int, int , .:)
, .