Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!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 11:33:08 +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 10:33:47 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="ySFDo36AujN+NJ7nQGUG6Q"; logging-data="27577"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18WAX4G8c8RRWJTEgoj3jOb" X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726 In-Reply-To: <289ad570-65fc-49d8-9cc8-1f15d13ff3e3@gv8g2000vbb.googlegroups.com> 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:ymJzbU25KWa6Rymp8QxlUrdjgro= X-Priority: 3 X-MSMail-Priority: Normal Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6113 comp.lang.c:8167 "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... Even if zero-overhead detection was possible, it's difficult to know how to make use of this in C. For example: 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; Even /with/ the overhead, it's difficult to see what could follow such an expression: if (overflow(c=a+b)) ... In the context of C-based code for implementing auto-ranging, dynamic types of /another language/, this might be workable, but still difficult to see how it can be done with zero-overhead. But this is a limited application (which I wouldn't even attempt in C because it's so fiddly). Aborting a program is also a possibility, but this just helps in debugging, and overheads are less relevant. (There is a longer thread on this in comp.lang.misc: "Integer arithmetic" from around start of March 2011.) -- Bartc