Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!feeder.news.tin.it!spool.news.tin.it!not-for-mail From: "io_x" Newsgroups: comp.lang.java.programmer,comp.lang.c 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> Subject: Re: Arithmetic overflow checking Date: Tue, 12 Jul 2011 09:05:12 +0200 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Lines: 31 Message-ID: <4e1bf1bc$0$15671$4fafbaef@reader2.news.tin.it> Organization: TIN.IT (http://www.tin.it) X-Comments: Please send technical notifications to newsmaster@tin.it NNTP-Posting-Host: 213.45.245.101 X-Trace: 1310454205 reader2.news.tin.it 15671 213.45.245.101:10838 X-Complaints-To: Please send abuse reports to abuse@retail.telecomitalia.it Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6102 comp.lang.c:8156 "tm" ha scritto nel messaggio news:3797038f-22d1-40b2-8c12-60db5a0976b8@t5g2000yqj.googlegroups.com... > On 8 Jul., 05:04, Patricia Shanahan wrote: >> On 7/7/2011 5:51 PM, Peter Duniho wrote: >> ... >> >> > I would not worry about the "simple" or "efficient" criteria. IMHO, if >> > one is deciding to apply overflow checking to every computation, one has >> > already abandoned the hope of efficiency. >> >> Not necessarily. I assumed a couple of decades ago that array index >> checking would be impossibly inefficient, but it seems to work fine in >> Java. > > And in other languages, like Pascal, Ada and Seed7, as well. > >> I suspect that having integer range types would be a major help. >> When I'm working out whether an int can overflow, I often think in terms >> of the ranges of inputs to calculations. A compiler would be able to >> tell that adding a digit to a digit always fits in the range [0,18]. > > I think there are two things: > > 1. range checks (like value fits in [0,18]). > 2. check if an 32-bit (or 8-bit, 16-bit, 64-bit, ...) > computation overflows. the carry flag for 2^n word is ok for detect overflow