Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!postnews.google.com!b2g2000vbo.googlegroups.com!not-for-mail From: tm Newsgroups: comp.lang.java.programmer,comp.lang.c Subject: Re: Arithmetic overflow checking Date: Tue, 12 Jul 2011 10:13:33 -0700 (PDT) Organization: http://groups.google.com Lines: 37 Message-ID: <20f66c93-c4a9-4060-b140-9ab04af2fdaa@b2g2000vbo.googlegroups.com> 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> NNTP-Posting-Host: 84.112.82.23 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1310490814 4042 127.0.0.1 (12 Jul 2011 17:13:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 12 Jul 2011 17:13:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b2g2000vbo.googlegroups.com; posting-host=84.112.82.23; posting-account=269_QwoAAADSifhJt6OVa6bEjZR2ZMUB User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESNKRC X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.2.18) Gecko/20110615 Ubuntu/10.10 (maverick) Firefox/3.6.18,gzip(gfe) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6124 comp.lang.c:8179 On 12 Jul., 18:26, markspace <-@.> wrote: > On 7/12/2011 6:16 AM, Stefan Ram wrote: > > > "BartC" =A0writes: > >> a+b overflows, but then what? > > > =A0 =A0This can only be answered given the requirements > > =A0 =A0specification of a specific project. > > What I think he's saying is there's no way physically detect the > overflow in a language like C which has no exceptions. But there are signals, which can be used for that purpose. Signals are also used for other exceptional things, like a division by zero. > You'd have to at > least introduce some sort of global flag. > > =A0 =A0int c =3D a + b; > =A0 =A0if( GLOBAL_OVERFLOW_FLAG ) { > =A0 =A0 =A0printf( "bugger..." ); > =A0 =A0} Checking a global flag is a bad idea, since it does not allow zero overhead arithmethic overflow detection (by CPUs which are able to trigger an interrupt on overflow). Greetings Thomas Mertes -- Seed7 Homepage: http://seed7.sourceforge.net Seed7 - The extensible programming language: User defined statements and operators, abstract data types, templates without special syntax, OO with interfaces and multiple dispatch, statically typed, interpreted or compiled, portable, runs under linux/unix/windows.