comp.lang.ada
 help / color / mirror / Atom feed
* Re: A case where Ada defaults to unsafe?
@ 2002-01-03 23:18 Gautier Write-only-address
  0 siblings, 0 replies; 120+ messages in thread
From: Gautier Write-only-address @ 2002-01-03 23:18 UTC (permalink / raw)
  To: comp.lang.ada

>From: Hyman Rosen <hyrosen@mail.com>

>It occurs to me that there is a case where the opposite seems to
>be true. In C/C++, the && and || binary operators short-circuit,
>evaluating their right operand only if necessary. In Ada, it is
>necessary to specify "and then" and "or else" for this behavior,
>otherwise the order of evaluation of the two sides is unspecified
>if the simple "and" and "or" forms are used.

Well, you are just explaining that in both languages,
the long form (&&, "and then") stands for short circuit, so what
is your point ?...

One language I know has a problem, it is Turbo Pascal and
maybe its descendent Delphi where a compiler switch decides
for the behaviour. E.g. a {$B-} will force the short-circuit
for the rest of the source file (or the next $B switch) !
But it is another story...

Happy programming (and new year)!
____________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/index.htm#Ada

NB: For a direct answer, address on the Web site!

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.




^ permalink raw reply	[flat|nested] 120+ messages in thread
* Re: A case where Ada defaults to unsafe?
@ 2002-01-07 16:45 Gautier Write-only-address
  2002-01-07 19:33 ` Ted Dennison
  0 siblings, 1 reply; 120+ messages in thread
From: Gautier Write-only-address @ 2002-01-07 16:45 UTC (permalink / raw)
  To: comp.lang.ada

> >The short circuit is not always the faster. A good compiler
> >can much more aggressively optimize an "x>=0 and x<=xmax" than
> >"x>=0 and then x<=xmax"; in addition "and then" introduces
> >branch(es) in the machine code, this is a performance
> >penalty on processors like the Pentiums.

Ted:

>Except that processors like the Pentiums also have branch prediction and
>speculative execution. So it might not matter much after all. :-)

You are speculating, I have tested.
BTW I was an "all short-circuit" fan before discovering that
it *is* slower for such expressions.

G.


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx




^ permalink raw reply	[flat|nested] 120+ messages in thread
* Re: A case where Ada defaults to unsafe?
@ 2002-01-05 12:47 Gautier Write-only-address
  2002-01-07 16:24 ` Ted Dennison
  0 siblings, 1 reply; 120+ messages in thread
From: Gautier Write-only-address @ 2002-01-05 12:47 UTC (permalink / raw)
  To: comp.lang.ada

>If I use "and" and I'm wrong in assuming that the order doesn't matter,
>then I have introduced a subtle bug. If I'm right, then I haven't gained
>anything. So why not always use "and then"?

The short circuit is not always the faster. A good compiler
can much more aggressively optimize an "x>=0 and x<=xmax" than
"x>=0 and then x<=xmax"; in addition "and then" introduces
branch(es) in the machine code, this is a performance
penalty on processors like the Pentiums.

____________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/index.htm#Ada

NB: For a direct answer, address on the Web site!


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx




^ permalink raw reply	[flat|nested] 120+ messages in thread
* Re: A case where Ada defaults to unsafe?
@ 2002-01-03 23:26 Gautier Write-only-address
  2002-01-03 23:54 ` Larry Hazel
  0 siblings, 1 reply; 120+ messages in thread
From: Gautier Write-only-address @ 2002-01-03 23:26 UTC (permalink / raw)
  To: comp.lang.ada

>From: Hyman Rosen <hyrosen@mail.com>

>But get away from C/C++ for a moment. In pure Ada terms, isn't it less safe
>for the defaults to be "and" and "or" instead of "and then" and "or else"?

In your divide-by-zero example, a beginner will find that
an "and" is less safe, but if "and" was an "and then", the
same beginner would not understand why "f and g" does not
work properly, where "f" and "g" have side-effects.

You should invent an "Ada for beginners" with "and also",
"and then" operators but no "and" ! Good luck...
____________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/index.htm#Ada

NB: For a direct answer, address on the Web site!


_________________________________________________________________
Join the world�s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com




^ permalink raw reply	[flat|nested] 120+ messages in thread
* A case where Ada defaults to unsafe?
@ 2002-01-03 20:29 Hyman Rosen
  2002-01-03 20:38 ` Darren New
                   ` (6 more replies)
  0 siblings, 7 replies; 120+ messages in thread
From: Hyman Rosen @ 2002-01-03 20:29 UTC (permalink / raw)


The conventional belief (at least on CLA :-) is that one of the
main distinctions between Ada and C/C++ is that Ada defaults to
safe behavior and C/C++ defaults to unsafe behavior (eg., array
indexing, automatic type conversions, and overflow checking).

It occurs to me that there is a case where the opposite seems to
be true. In C/C++, the && and || binary operators short-circuit,
evaluating their right operand only if necessary. In Ada, it is
necessary to specify "and then" and "or else" for this behavior,
otherwise the order of evaluation of the two sides is unspecified
if the simple "and" and "or" forms are used.

So in Ada, one could say 'if a /= 0 and b/a > 3' and fall into a
trap that would not happen in C/C++. Discuss?




^ permalink raw reply	[flat|nested] 120+ messages in thread

end of thread, other threads:[~2002-01-20 21:19 UTC | newest]

Thread overview: 120+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-03 23:18 A case where Ada defaults to unsafe? Gautier Write-only-address
  -- strict thread matches above, loose matches on Subject: below --
2002-01-07 16:45 Gautier Write-only-address
2002-01-07 19:33 ` Ted Dennison
2002-01-05 12:47 Gautier Write-only-address
2002-01-07 16:24 ` Ted Dennison
2002-01-07 18:17   ` FGD
2002-01-07 18:21     ` Hyman Rosen
2002-01-07 20:26       ` Matthew Woodcraft
2002-01-07 21:16         ` Hyman Rosen
2002-01-13  8:23           ` Hyman Rosen
2002-01-13  9:06             ` Preben Randhol
2002-01-13 10:41             ` Larry Kilgallen
2002-01-14  5:47               ` Hyman Rosen
2002-01-14 12:41               ` Georg Bauhaus
2002-01-13 18:21             ` Michal Nowak
2002-01-14  1:29               ` Ted Dennison
2002-01-14 14:36                 ` Ted Dennison
2002-01-14 22:43                 ` Michal Nowak
2002-01-10 20:47         ` Robert A Duff
2002-01-10 23:37           ` Preben Randhol
2002-01-11  1:31             ` Robert A Duff
2002-01-11 20:32               ` Nick Roberts
2002-01-11 16:47           ` Hyman Rosen
2002-01-03 23:26 Gautier Write-only-address
2002-01-03 23:54 ` Larry Hazel
2002-01-04 14:33   ` Robert A Duff
2002-01-03 20:29 Hyman Rosen
2002-01-03 20:38 ` Darren New
2002-01-03 21:36   ` Hyman Rosen
2002-01-04 14:29     ` Wes Groleau
2002-01-03 21:27 ` James Rogers
2002-01-03 21:32 ` Frank J. Lhota
2002-01-03 21:51   ` Hyman Rosen
2002-01-03 22:22     ` Ted Dennison
2002-01-03 23:07       ` Hyman Rosen
2002-01-03 23:38         ` Nick Williams
2002-01-04  0:15         ` Florian Weimer
2002-01-04  7:40         ` Preben Randhol
2002-01-04 14:39         ` Wes Groleau
2002-01-04 15:16         ` Ted Dennison
2002-01-04  3:35       ` Eric Merritt
2002-01-04 14:39         ` Robert A Duff
2002-01-04 14:27     ` Robert A Duff
2002-01-04 15:39       ` Larry Kilgallen
2002-01-04 15:57       ` Ted Dennison
2002-01-04 16:05       ` Ted Dennison
2002-01-10 21:22         ` Robert A Duff
2002-01-11  9:14           ` Dmitry A. Kazakov
2002-01-04 16:19       ` Brian Rogoff
2002-01-04 16:31         ` Ted Dennison
2002-01-08 20:55         ` Mark Lundquist
2002-01-16  0:14           ` Matthew Heaney
2002-01-16 20:19             ` Robert A Duff
2002-01-10 21:29         ` Robert A Duff
2002-01-11  9:25           ` Dmitry A. Kazakov
2002-01-19  0:35           ` Brian Rogoff
2002-01-19 14:15             ` Robert A Duff
2002-01-19 23:10               ` Brian Rogoff
2002-01-04 16:29     ` Robert Dewar
2002-01-04 17:32       ` Hyman Rosen
2002-01-04 18:50         ` Matthew Heaney
2002-01-04 18:56           ` Darren New
2002-01-04 19:10           ` Hyman Rosen
2002-01-04 20:08             ` Matthew Heaney
2002-01-04 20:14               ` Ted Dennison
2002-01-04 20:20               ` Hyman Rosen
2002-01-04 21:16                 ` Larry Kilgallen
2002-01-04 21:33                 ` Ted Dennison
2002-01-07 15:39                   ` Hyman Rosen
2002-01-07 16:06                     ` Ted Dennison
2002-01-07 16:50                     ` Larry Kilgallen
2002-01-07 17:18                       ` Hyman Rosen
2002-01-07 17:26                         ` Pat Rogers
2002-01-07 18:12                           ` Hyman Rosen
2002-01-07 18:40                             ` FGD
2002-01-07 20:04                             ` Pat Rogers
2002-01-05  0:08             ` Nick Roberts
2002-01-05 10:57               ` Simon Wright
2002-01-08 23:27                 ` Nick Roberts
2002-01-09  9:58                   ` Stuart Palin
2002-01-09 11:11                     ` Nick Roberts
2002-01-10 20:32                     ` Robert A Duff
2002-01-11  9:45                       ` Stuart Palin
2002-01-11 13:32                         ` Robert A Duff
2002-01-14 13:14                           ` Stuart Palin
2002-01-14 14:38                             ` Preben Randhol
2002-01-16  6:00                             ` Simon Wright
2002-01-17  3:04                               ` David Starner
2002-01-17 15:08                                 ` Georg Bauhaus
2002-01-17 20:25                                   ` Simon Wright
2002-01-17  9:56                               ` Stuart Palin
     [not found]                           ` <3 <3C469FE6.B2C67ED6@baesystems.com>
2002-01-17 20:32                             ` Simon Wright
2002-01-14 14:35                         ` Preben Randhol
2002-01-14 16:36                         ` Robert A Duff
2002-01-12 12:27                   ` Simon Wright
2002-01-05  0:32         ` Robert Dewar
2002-01-14 16:09     ` Matthieu Moy
2002-01-20  8:59       ` Hyman Rosen
2002-01-20 19:13         ` Jim Rogers
2002-01-20 21:19           ` Ray Blaak
2002-01-03 22:07 ` Ted Dennison
2002-01-04 17:12   ` Preben Randhol
2002-01-04 17:21     ` Jean-Marc Bourguet
2002-01-04 18:54     ` Ted Dennison
2002-01-04  3:17 ` Larry Kilgallen
2002-01-04  8:27 ` Thierry Lelegard
2002-01-04  8:39   ` tmoran
2002-01-04  9:03     ` Thierry Lelegard
2002-01-04 14:43       ` Wes Groleau
2002-01-04 15:45       ` Ted Dennison
2002-01-04 16:37         ` Wes Groleau
2002-01-04 16:56           ` Ted Dennison
2002-01-04 11:51   ` Larry Kilgallen
2002-01-04 12:41   ` M. A. Alves
2002-01-04 15:42   ` Ted Dennison
2002-01-04 17:16     ` Hyman Rosen
2002-01-04 19:12       ` Ted Dennison
2002-01-04 23:36   ` Matthew Woodcraft
2002-01-05 15:00 ` Steve Doiel
2002-01-10 20:49   ` Robert A Duff

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