long conversion of short expression.

Philip Lantz prl at inteloa.intel.com
Thu Aug 3 13:48:59 AEST 1989


In article <18795 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
> The result of shortvar*shortvar has type int.
> ...         If the result overflows, the value is undefined; a clever
> int-is-16-bits-style 68000 compiler may produce the correct value by
> noticing that the 68000 `muls' instruction produces a 32 bit result,
> and carrying that around even though its result type (int) was supposed
> to have been only 16 bits.  This is not required by any C standard,
> but is permitted since the result value is undefined.

I agree that if the multiplication overflows, the result is undefined,
but its type is still an int; if a later conversion to long is
required, isn't the compiler required to perform the 'extl' anyway?
That is, shouldn't the result of a conversion from int to long be in
the numeric range of an int, even if the original int value was
undefined?  Or is the compiler free to do whatever it likes with an
entire expression if any sub-expression overflows?

Philip Lantz

P.S.  Sorry to pick nits, Chris; your articles are without fail the most
accurate and informative in this newsgroup.



More information about the Comp.lang.c mailing list