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!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.7.8) Gecko/20050511 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Division by zero References: <79ahr0jozmqb$.10jzllrcjpmsv.dlg@40tude.net> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Sun, 12 Jun 2005 16:55:05 GMT NNTP-Posting-Host: 67.3.225.48 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.pas.earthlink.net 1118595305 67.3.225.48 (Sun, 12 Jun 2005 09:55:05 PDT) NNTP-Posting-Date: Sun, 12 Jun 2005 09:55:05 PDT Xref: g2news1.google.com comp.lang.ada:11300 Date: 2005-06-12T16:55:05+00:00 List-Id: Robert A Duff wrote: > Well, in Ada 83, the "class of errors" was "divide by zero". > In Ada 95, that was split into "divide by zero in a static expression" > and "divide by zero in a nonstatic expression" -- the former is a > compile time error, whereas the latter is a run-time error. > There's nothing illogical about splitting it further: > "divide by zero when the Right operand is static" could be defined > as a compile-time error. The problem is that if you try to define > all the compile-time-detectable cases very precisely, it gets quite > complicated. And however you define it, it *has* to be conservative. The problem, it seems to me, is that the developer may deliberately write a division of a variable by static zero for a number of reasons. He may want it to raise Constraint_Error at run time, or may have redefined "/" for the type of the variable to do something meaningful if the divisor is zero. This latter case invalidates an earlier example. The following should compile and output Integer'Last before terminating normally: with Ada.Text_IO; procedure Zero_Div is function "/" (Left : Integer; Right : Integer) return Integer is -- null; begin -- "/" if Right = 0 then return Integer'Last; else return Left / Right; end if; end "/"; A : constant Integer := 23; B : constant Integer := 0; begin -- Zero_Div Ada.Text_IO.Put_Line (Item => Integer'Image (A / B) ); end Zero_Div; -- Jeff Carter "Don't knock masturbation. It's sex with someone I love." Annie Hall 45