comp.lang.ada
 help / color / mirror / Atom feed
From: "Lurker" <nowhere@nothing.com>
Subject: Re: Division by zero
Date: Sun, 12 Jun 2005 21:43:16 +1200
Date: 2005-06-12T21:43:16+12:00	[thread overview]
Message-ID: <RqTqe.6788$U4.973079@news.xtra.co.nz> (raw)
In-Reply-To: 79ahr0jozmqb$.10jzllrcjpmsv.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:79ahr0jozmqb$.10jzllrcjpmsv.dlg@40tude.net...

> > 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.

OK, I see you point. But, pratically speaking, the chances are that
that construct was an error. Perhaps a warning or some such would
be enough. If whoever wrote that was sure that's what they meant - fine.
But I was always under the impression that the Ada philosophy was
to avoid accidental mistakes as much as possible. And division by
zero sure should qualify as a suspect at least - not something that
just happily gets compiled.

> >> 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. (:-))

I'm afraid I don't follow your logic there. Do you really mean that
a constant declared as = 0 cannot be detected at compile time?

Yes, the effects of using it to divide something may or may not be ok.
But that would equally apply to dividing a literal 1 by it, wouldn't it?

(Again, I realise your point about static vs other expressions.
But c'mon, unless someone specifically allows and handles
cases like that, surely the safest bet would be to at least point
out that there is something fishy going on and a "moral equivalent"
of asking "are you sure"?
>
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de





  reply	other threads:[~2005-06-12  9:43 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 [this message]
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
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