From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e01fe1b326df26d4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!news.xtra.co.nz!53ab2750!not-for-mail From: "Lurker" Newsgroups: comp.lang.ada References: Subject: Re: Division by zero X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 Message-ID: Date: Sun, 12 Jun 2005 15:04:17 +1200 NNTP-Posting-Host: 219.88.100.113 X-Complaints-To: abuse@xtra.co.nz X-Trace: news.xtra.co.nz 1118545327 219.88.100.113 (Sun, 12 Jun 2005 15:02:07 NZST) NNTP-Posting-Date: Sun, 12 Jun 2005 15:02:07 NZST Organization: Xtra Xref: g2news1.google.com comp.lang.ada:11290 Date: 2005-06-12T15:04:17+12:00 List-Id: "David C. Hoos, Sr." wrote in message news:mailman.16.1118541539.17633.comp.lang.ada@ada-france.org... > The reason for the difference is that because both terms of line 1 > are known at compile time, the computation is performed at compile > time, and thus raises the exception. > > Since the numerator of line 2 is a variable, the compiler does not > attempt any computation, and thus does not signal an error. Well, yes. But can't it tell that division by zero is always wrong regardless? What has actually happened (outside that toy example) was that there was a constant declared in one place and used in many others. Someone went ahead and changed it (for a good reason) to zero. However, one of the uses of that constant was to divide by it. > > Constraint_Error will be raised at runtime. It was. My question was - should it have been caught at compile time instead? > > ----- Original Message ----- > From: "Lurker" > Newsgroups: comp.lang.ada > To: > Sent: June 11, 2005 4:03 PM > Subject: Division by zero > > > > Hi, > > > > I'm curios about the problem which I discovered by accident. > > The code below is of course very much reduced to show > > the it: > > > > function x(a: integer) return integer is > > > > some_constant: constant := 0; > > > > begin > > > > -- return 1/some_constant; -- line 1 > > > > -- return a/some_constant; -- line 2 > > > > end; > > > > > > > > If line 1 is uncommented compiler (Gnat 3.15 for Widows) > > > > produces the expected error about division by zero. > > > > If line 2 is uncommented it passes compilation with no problem. > > > > Surely that's not right? Or did I miss something? > > > > > > > > > > _______________________________________________ > > comp.lang.ada mailing list > > comp.lang.ada@ada-france.org > > http://www.ada-france.org/mailman/listinfo/comp.lang.ada > > > >