long conversion of short expression.

Doug Gwyn gwyn at smoke.BRL.MIL
Mon Jul 31 23:49:21 AEST 1989


In article <869 at fiasco.sco.COM> md at sco.COM (Michael Davidson) writes:
>Neither - the two (short) variables are promoted to (int) before the
>multiplication, the result of the multiplication is an (int) ...
>Of course your compiler can generate any code it likes provided that
>it gets the answer which is "correct" according to these rules.

Oops, Michael is correct.  I misstated this in an earlier response.
The "usual arithmetic conversions" are applied to the operands before
the operation occurs, and the result has the common promoted type.
Anyway, the important point is that the programmer needs to use
explicit casts to force the shorts to longs if the result might not
fit in a short.



More information about the Comp.lang.c mailing list