Re: Division by zero
- From: Robert A Duff <bobduff@xxxxxxxxxxxxxxxxxxxx>
- Date: 29 Jun 2005 09:27:01 -0400
"Lurker" <nowhere@xxxxxxxxxxx> writes:
> "Robert A Duff" <bobduff@xxxxxxxxxxxxxxxxxxxx> wrote in message
> news:wccy88ugorw.fsf@xxxxxxxxxxxxxxxxxxxxxxx
>
> > 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?
Just to be cleear, we're talking about whether X/Y should be illegal
when Y is a static expression equal to 0. It is illegal if X is also
static, but it is legal if X is nonstatic.
The reason is that it simplifies the language definition. For any
particular "kind" of error, the language design style used for Ada is to
choose one of:
- always detect this error at compile time
- always detect this error at run time
For division by zero, it is believed to be too restrictive to detect it
at compile time. Therefore it's a run-time error. And we trust
compilers to give warnings in cases that can be detected at compile
time. But it would complicate the language definition to describe such
cases, and it would not be clear how "smart" to require the compiler to
be.
Static expressions are special, though: the compiler needs to know the
value of the expression, at last sometimes. We have to make things like
this:
T'First(1/0)
illegal, for example, because the type of that expression depends on the
value of 1/0, which doesn't make sense.
(In the above, I'm ignoring the rare cases of errors that are not
detected at all, or are detected at link time, etc.)
> Please excuse all examples of custom "/" definitions. Let's assume
> we are talking about predefined division operation on integers.
I agree -- everybody is confusing the issue by talking about
user-defined functions that happen to be called "/".
We're talking about predefined division only.
> Why would division by zero be allowed? (If you want to redefine
> your operations, then all bets are off of course, but what about
> the default ones?)
- Bob
.
- Follow-Ups:
- Re: Division by zero
- From: Lurker
- Re: Division by zero
- From: Dmitry A. Kazakov
- Re: Division by zero
- References:
- Division by zero
- From: Lurker
- Re: Division by zero
- From: David C. Hoos, Sr.
- Re: Division by zero
- From: Lurker
- Re: Division by zero
- From: Dmitry A. Kazakov
- Re: Division by zero
- From: Robert A Duff
- Re: Division by zero
- From: Jeffrey Carter
- Re: Division by zero
- From: Robert A Duff
- Re: Division by zero
- From: Lurker
- Re: Division by zero
- From: Robert A Duff
- Re: Division by zero
- From: Lurker
- Division by zero
- Prev by Date: Re: Division by zero
- Next by Date: Re: Division by zero
- Previous by thread: Re: Division by zero
- Next by thread: Re: Division by zero
- Index(es):
Relevant Pages
|
Loading