comp.lang.ada
 help / color / mirror / Atom feed
* RE: Exceptions vs. if-then-else
@ 1991-03-21 18:07 Ray Diederich (301)-294-8400
  1991-03-26  2:26 ` Jim Showalter
  0 siblings, 1 reply; 2+ messages in thread
From: Ray Diederich (301)-294-8400 @ 1991-03-21 18:07 UTC (permalink / raw)


In article <jls.669368339@rutabaga> jls@rutabaga.Rational.COM (Jim Showalter) writes:
>>procedure pop(s: stack)
>>begin
>>   if(not empty(s)) then
>>      -- pop the stack
>>   else
>>      raise underflow
     end if;
>>end pop;
>
>>procedure pop(s: stack)
>>begin
>>   stack.top := stack.top - 1;
>>   exception
>>      when Constraint_Error => raise underflow
>>end pop;

[stuff deleted]

> Not only is it faster, it is safer, since
> without using tasks you cannot guarantee that between the time you
> checked and the time you popped it hadn't been popped elsewhere.
(I assume the statement is meant to read "... safer, since _when_ using
tasks ..." rather than "... safer, since _without_ using tasks ...".)

I don't know of any machine nor compiler which guarrantees that an Ada
statement is non-interruptible. Some machines don't even guarrantee that
a decrement memory location machine instruction is atomic. I see little
difference in the degree of safety here; certainly not enough to sacrifice
the clarity of the first example.

Ray Diederich

GTE Government Systems Corporation
Strategic Electronic Defense Division
National Center Systems Directorate
(Yup, that's GTE, alias monolithic corporation)
========================================
The opinions expressed here are not necessarily those of my employer, my
country, my family, or even myself.
========================================

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

end of thread, other threads:[~1991-03-26  2:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-03-21 18:07 Exceptions vs. if-then-else Ray Diederich (301)-294-8400
1991-03-26  2:26 ` Jim Showalter

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