checking for overflow in C

Henry Spencer henry at utzoo.uucp
Wed May 10 04:31:40 AEST 1989


In article <8143 at june.cs.washington.edu> ka at june.cs.washington.edu (Kenneth Almquist) writes:
>> ... There is no consensus on whether the hardware checks for overflow
>> or not....
>If there is not a consensus, there is certainly an overwhelming majority!
>I know the assembly languages of half a dozen machines, and they all
>include overflow checks.

But not as part of the multiply instruction.  They are extra-cost tests,
typically at the very least a conditional branch following the multiply.
This gets expensive when you know that your multiplies never overflow, which
is why C compilers typically do not generate those tests.  Note that I said
"on whether the *hardware* checks for overflow" (emphasis added), not
"on whether the software checks for overflow".
-- 
Mars in 1980s:  USSR, 2 tries, |     Henry Spencer at U of Toronto Zoology
2 failures; USA, 0 tries.      | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list