comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Division by zero
Date: Thu, 30 Jun 2005 10:27:36 +0200
Date: 2005-06-30T10:27:36+02:00	[thread overview]
Message-ID: <124p08chez60n$.1w8hv68z2egog.dlg@40tude.net> (raw)
In-Reply-To: wcc64vxp2nf.fsf@shell01.TheWorld.com

On 29 Jun 2005 12:07:48 -0400, Robert A Duff wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
>> On Wed, 29 Jun 2005 17:50:43 +1200, Lurker wrote:
>> 
>>> "Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message
>>> news:wccy88ugorw.fsf@shell01.TheWorld.com...
>>> 
>>>> 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?
>> 
>> Because within *one* type [Integer in this case] it is a halting problem:
>> 
>> declare
>>    A : Integer := 1;
>>    B : Integer;
>> begin
>>    if HALT (x) then
>>       B := 0;
>>    else
>>       B := 1;
>>    end if;
>>    A := A / B;
>> end;
> 
> Sorry, but I think you were confused by my sloppy wording.
> The question was not whether divide-by-zero should be illegal
> in the general case.  The question was whether X/Y should be
> illegal when Y is static, but X is not.

Yes, this is why I mentioned "one type". Without breaking the type system,
it would be difficult to make X/0 illegal.

A possible scenario: Universal_Integer is converted to Integer and then "/"
is called. Let we want zero divide to be illegal. Then we could introduce:

function "/" (Left : Integer; Right : Universal_Integer) return Integer;

overloaded with what we have now:

function "/" (Left, Right : Integer) return Integer;
function "/" (Left, Right : Universal_Integer) return Universal_Integer;

Fine, but what would happen if "/" gets overridden? This would open a can
of worms, because the result of X/Y would depend on whether Y is static!
OK, it already depends if both are static. But making it dependant on the
basis of individual values? This may lead to fine effects very difficult to
catch, so in the end, safety would rather lost than gained.

> Even in your example above, there's a good argument that the compiler
> should (optionally) warn.  That example looks buggy to me!

Yes. I think that warning about run-time C_E would be more appropriate
here.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2005-06-30  8:27 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
2005-06-29 13:50                   ` Dmitry A. Kazakov
2005-06-29 16:07                     ` Robert A Duff
2005-06-30  8:27                       ` Dmitry A. Kazakov [this message]
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