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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Division by zero Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Sun, 12 Jun 2005 10:39:16 +0200 Message-ID: <79ahr0jozmqb$.10jzllrcjpmsv.dlg@40tude.net> NNTP-Posting-Date: 12 Jun 2005 10:39:11 MEST NNTP-Posting-Host: 9e0deec9.newsread4.arcor-online.net X-Trace: DXC=SVODVHno On Sun, 12 Jun 2005 15:04:17 +1200, Lurker wrote: > "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? No, it is not, because it has a defined effect: Constraint_Error. Formally speaking division by zero is not a contract violation and thus cannot be "wrong". Consider the following: A : constant Integer := 0; B : Integer := 1; begin B := B / A; Put_Line ("Hello!"); exception when others => Put_Line ("Good bye!"); The above is a valid program, which should print "Good bye!". At the same time the following is *wrong*: A : constant Integer := 0; B : constant Integer := 1; C : Integer; begin C := B / A; B/A is a static expression, which has to have a value at compile-time. The difference is not in what the compiler might know, but in what it must know. > 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? I don't think it should. A class of errors which cannot be detected at compile time cannot be compile-time errors. Or, in other words, if you cannot rely on the compiler, you should not pretend you can. (:-)) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de