comp.lang.ada
 help / color / mirror / Atom feed
From: diederich_r_%ncsd.dnet@GTE.COM (Ray Diederich (301)-294-8400)
Subject: RE: Exceptions vs. if-then-else
Date: 21 Mar 91 18:07:13 GMT	[thread overview]
Message-ID: <9103211807.AA22650@bunny.gte.com> (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.
========================================

             reply	other threads:[~1991-03-21 18:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-03-21 18:07 Ray Diederich (301)-294-8400 [this message]
1991-03-26  2:26 ` Exceptions vs. if-then-else Jim Showalter
replies disabled

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