Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: "BartC" Newsgroups: comp.lang.java.programmer,comp.lang.c Subject: Re: Arithmetic overflow checking Date: Tue, 12 Jul 2011 12:33:26 +0100 Organization: A noiseless patient Spider Lines: 2 Message-ID: References: <015aeb15-57db-48ab-9cd4-77f8448b632f@w24g2000yqw.googlegroups.com> <2rydnez7l-H5BYnTnZ2dnUVZ_vGdnZ2d@earthlink.com> <9LWdnZH2hdfmyYvTnZ2dnUVZ_vidnZ2d@posted.palinacquisition> <3797038f-22d1-40b2-8c12-60db5a0976b8@t5g2000yqj.googlegroups.com> <289ad570-65fc-49d8-9cc8-1f15d13ff3e3@gv8g2000vbb.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit Injection-Date: Tue, 12 Jul 2011 11:34:01 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="ySFDo36AujN+NJ7nQGUG6Q"; logging-data="15807"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19sIQ40kKnJU7YnakVR9dhE" X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726 In-Reply-To: X-Antivirus-Status: Clean X-Newsreader: Microsoft Windows Live Mail 14.0.8089.726 Importance: Normal X-Antivirus: avast! (VPS 110712-0, 12/07/2011), Outbound message Cancel-Lock: sha1:N6pKoLKdEhOUYWMF8rANlt0c2Yc= X-Priority: 3 X-MSMail-Priority: Normal Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6116 comp.lang.c:8170 "tm" wrote in message news:a642c317-92bf-47a3-995a-2839d17c98ba@cq10g2000vbb.googlegroups.com... > On 12 Jul., 12:33, "BartC" wrote: >> "tm" wrote in message >> >> news:289ad570-65fc-49d8-9cc8-1f15d13ff3e3@gv8g2000vbb.googlegroups.com... >> >> > And popular CPUs, which do detect integer overflow, do not >> > trigger an interupt. This makes zero overhead overflow >> > detection impossible. >> >> > So software suffers because hardware / CPU designers want >> > to save a transistor... >> int a,b,c; >> >> c=a+b; >> >> The a+b overflows, but then what? You can't then magically switch over >> to: >> >> long long int a,b,c; > > No, when a+b overflows, there is a bug in the program. > The purpose of overflow detection is NOT support for > unlimited precision integers. When the programmer thinks, > that all his computations will fit in an int, he can use > it (for performance or other reasons). In this case > he probably wants to know when his approach was wrong. > > Most programmers want correct results, or the > information that something went wrong. Reasons where > wrong results are acceptable should be left out from > this discussion. OK, so it's for debugging purposes. In this case, any overhead (of extra instructions to check flags and interrupt or whatever) is less important, and can be (and needs to be) optional. -- Bartc