short a;
short b;
short x;
int c = (int)a + (int)b * (int)x;
Can I dispense with the (int) casts in this case? i.e. when compiler performs the multiply and add, does it work with int intermediate variables, or with short intermediate variables?
Edit: what about for 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
can overflow, because b*x is calculated using int arithmetic. The safer expression is:
int64 c = a + (int64)b * (int64)x;