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.9 required=5.0 tests=BAYES_00,FROM_NUMERIC_TLD 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!news1.google.com!news2.google.com!proxad.net!proxad.net!feeder2.cambrium.nl!feed.tweaknews.nl!border2.nntp.ams.giganews.com!nntp.giganews.com!newsfeeder.wxs.nl!zen.net.uk!dedekind.zen.co.uk!news-peer-lilac.gradwell.net!not-for-mail Message-ID: <42C3D49D.F7515E54@0.0> Date: Thu, 30 Jun 2005 12:16:45 +0100 From: Stuart Palin X-Mailer: Mozilla 4.5 [en] (WinNT; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Division by zero References: <79ahr0jozmqb$.10jzllrcjpmsv.dlg@40tude.net> <_pwre.7121$U4.1023104@news.xtra.co.nz> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Original-NNTP-Posting-Host: glkas0286.greenlnk.net NNTP-Posting-Date: 30 Jun 2005 11:17:46 GMT NNTP-Posting-Host: 20.133.0.1 X-Trace: 1120130266 news.gradwell.net 38043 dnews/20.133.0.1 X-Complaints-To: news-abuse@gradwell.net Xref: g2news1.google.com comp.lang.ada:11758 Date: 2005-06-30T11:17:46+00:00 List-Id: Lurker wrote: > > "Robert A Duff" wrote in message > > The reason is that it simplifies the language definition. > > You don't seem to find any problem with complicating > the language definition in the case of static expressions though. > And, detecting division by static zero should be a non-issue > really. But evaluating static expressions is a general rule that can support error detection in a wide range of cases - basically all the predefined operators. Consider: type T is range 1..10; x, y : T; ... x := 5 + 6; -- Constraint error will be raised! or y := x + 10; -- Constraint Error will be raised! [GNAT produces warnings that constraint error will be raised in these cases] If you are adding a rule for "/", what about the other operators (which also include "mod" and "rem"). If you don't have the additional rules the language starts to appear arbitrary: now you have to start remembering what all the arbitrary rules are. As has been said elsewhere, you can add the rules but they make the compiler more complex (and if you are not careful can interact with other rules in unexpected ways). It is right that the Ada standard considers both the benefit and cost of the rules. Personally I think the standard has got it right in this case: it has defined a generic rule that has benefits and seems to be little cost to the compiler (it will most likely want to evaluate static expressions at compile time). > Sorry, I still don't see how complex it would be. If an expression is > static, compiler knows it at compile time, correct? So let's say the > rule is that predefined division operation is illegal if the static > divisor evaluates to zero. But how complicated will the language become if everyone's pet 'simple rule' got put in. There are tools available for carrying out much more detailed analysis of code behaviour (e.g. SPARK & Polyspace). For people really concerned with errors in their code (not just divide by zero) they offer automated ways of detecting them. Regards -- Stuart