long conversion of short expression.

Michael Davidson md at sco.COM
Mon Jul 31 03:04:36 AEST 1989


In article <9092 at chinet.chi.il.us> pdg at chinet.chi.il.us (Paul Guthrie) writes:
>Here is a case where 68000 compilers don't seem to agree. 
>In the following code segment, the two shorts multiplied together
>exceed the size of a short, but the question is, is the result
>of the multiplication really a short to be converted to a
>long, or a long already?
Neither - the two (short) variables are promoted to (int) before the
multiplication, the result of the multiplication is an (int) which
gets promoted to a (long) before the addition is performed.
Of course your compiler can generate any code it likes provided that
it gets the answer which is "correct" according to these rules.
(To see why understanding this particular bit of pedantry is important
consider what happens on machines with 16 bit shorts, 16 bit ints and
32 bit longs)



More information about the Comp.lang.c mailing list