comp.lang.ada
 help / color / mirror / Atom feed
From: Stuart Palin <stuart.palin@0.0>
Subject: Re: Division by zero
Date: Thu, 30 Jun 2005 12:16:45 +0100
Date: 2005-06-30T11:17:46+00:00	[thread overview]
Message-ID: <42C3D49D.F7515E54@0.0> (raw)
In-Reply-To: dJHwe.11417$U4.1452456@news.xtra.co.nz

Lurker wrote:
> 
> "Robert A Duff" <bobduff@shell01.TheWorld.com> 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



  reply	other threads:[~2005-06-30 11:16 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-11 21:03 Division by zero Lurker
2005-06-12  2:00 ` David C. Hoos, Sr.
2005-06-12  3:04   ` Lurker
2005-06-12  8:39     ` Dmitry A. Kazakov
2005-06-12  9:43       ` Lurker
2005-06-12 10:36         ` Marius Amado Alves
2005-06-12 11:53         ` Dmitry A. Kazakov
2005-06-13  8:03         ` Ole-Hjalmar Kristensen
2005-06-12 13:10       ` Robert A Duff
2005-06-12 16:55         ` Jeffrey Carter
2005-06-13  3:22           ` Keith Thompson
2005-06-14  2:14             ` Jeffrey Carter
2005-06-13  8:47           ` Lurker
2005-06-14  2:19             ` Jeffrey Carter
2005-06-14  8:35               ` Keith Thompson
2005-06-13 12:19           ` Robert A Duff
2005-06-14  2:31             ` Jeffrey Carter
2005-06-14  8:21             ` Lurker
2005-06-14 20:22               ` Randy Brukardt
2005-06-28 21:22               ` Robert A Duff
2005-06-29  5:50                 ` Lurker
2005-06-29 13:27                   ` Robert A Duff
2005-06-29 13:54                     ` Dmitry A. Kazakov
2005-06-29 16:03                       ` Robert A Duff
2005-06-30  1:19                     ` Lurker
2005-06-30 11:16                       ` Stuart Palin [this message]
2005-06-29 13:50                   ` Dmitry A. Kazakov
2005-06-29 16:07                     ` Robert A Duff
2005-06-30  8:27                       ` Dmitry A. Kazakov
2005-06-29  9:20                 ` Lurker
2005-06-29  9:49                   ` Christoph Grein
2005-06-29 10:40                     ` Lurker
2005-06-29 11:04                       ` Jeff Creem
2005-06-29 12:28                         ` Martin Dowie
2005-06-29 13:40                   ` Robert A Duff
     [not found]     ` <5sana1pm436l6vboifijqblu0irf84afkr@4ax.com>
2005-06-12 17:38       ` Simon Wright
2005-06-12 12:21 ` Robert A Duff
2005-06-12 22:53 ` Georg Bauhaus
2005-06-13  8:34   ` Lurker
2005-06-13  8:54     ` Marius Amado Alves
2005-06-13 17:59       ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox