Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: checking for overflow in C Message-ID: <1989May9.183140.1770@utzoo.uucp> Organization: U of Toronto Zoology References: <13367@dartvax.Dartmouth.EDU> <1989May6.224226.22085@utzoo.uucp> <8143@june.cs.washington.edu> Date: Tue, 9 May 89 18:31:40 GMT In article <8143@june.cs.washington.edu> ka@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@zoo.toronto.edu