Re: Division by zero



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



Relevant Pages

  • Re: Division 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. ...
    (comp.lang.ada)
  • Re: D3/Linux compile question
    ... 02 equ a to x ... Variable has not been assigned a value; zero used. ... Based on the actual compile I'm not sure. ... base frame not 1 past the base frame. ...
    (comp.databases.pick)
  • Re: Two problems
    ... uninitialised variables that I really should be clearing to zero ... I don't need a statement clearing the variable ... In one case they are set to zero or some other ... enabled and turn on all of the compile time warnings you can. ...
    (comp.lang.fortran)
  • Re: Two problems
    ... uninitialised variables that I really should be clearing to zero ... I don't need a statement clearing the variable ... In one case they are set to zero or some other ... enabled and turn on all of the compile time warnings you can. ...
    (comp.lang.fortran)
  • Re: Use of memcpy() to transfer from memory to a variable
    ... It is if it produces a trap representation in the 'long' variable. ... where it can produce negative zero, which can be a trap representation. ... it's possible to trap it at compile time by checking that ... memcpy(&value, pAddress, rem); ...
    (comp.lang.c)

Loading