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: <79ahr0jozmqb$.10jzllrcjpmsv.dlg@40tude.net> <_pwre.7121$U4.1023104@news.xtra.co.nz> Date: Thu, 30 Jun 2005 10:27:36 +0200 Message-ID: <124p08chez60n$.1w8hv68z2egog.dlg@40tude.net> NNTP-Posting-Date: 30 Jun 2005 10:27:36 MEST NNTP-Posting-Host: 2ab6c119.newsread4.arcor-online.net X-Trace: DXC=45WKCZ99PJ9JeejX On 29 Jun 2005 12:07:48 -0400, Robert A Duff wrote: > "Dmitry A. Kazakov" writes: > >> On Wed, 29 Jun 2005 17:50:43 +1200, Lurker wrote: >> >>> "Robert A Duff" wrote in message >>> news:wccy88ugorw.fsf@shell01.TheWorld.com... >>> >>>> 11.6(5) is all about run time effects. If divide by zero were illegal >>>> (which means at compile time), then 11.6 would not apply. >>> >>> Which brings us back to my original question - why is it legal? >> >> Because within *one* type [Integer in this case] it is a halting problem: >> >> declare >> A : Integer := 1; >> B : Integer; >> begin >> if HALT (x) then >> B := 0; >> else >> B := 1; >> end if; >> A := A / B; >> end; > > Sorry, but I think you were confused by my sloppy wording. > The question was not whether divide-by-zero should be illegal > in the general case. The question was whether X/Y should be > illegal when Y is static, but X is not. Yes, this is why I mentioned "one type". Without breaking the type system, it would be difficult to make X/0 illegal. A possible scenario: Universal_Integer is converted to Integer and then "/" is called. Let we want zero divide to be illegal. Then we could introduce: function "/" (Left : Integer; Right : Universal_Integer) return Integer; overloaded with what we have now: function "/" (Left, Right : Integer) return Integer; function "/" (Left, Right : Universal_Integer) return Universal_Integer; Fine, but what would happen if "/" gets overridden? This would open a can of worms, because the result of X/Y would depend on whether Y is static! OK, it already depends if both are static. But making it dependant on the basis of individual values? This may lead to fine effects very difficult to catch, so in the end, safety would rather lost than gained. > Even in your example above, there's a good argument that the compiler > should (optionally) warn. That example looks buggy to me! Yes. I think that warning about run-time C_E would be more appropriate here. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de