From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: *** X-Spam-Status: No, score=3.9 required=5.0 tests=BAYES_50,INVALID_DATE, PDS_OTHER_BAD_TLD autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!GTE.COM!diederich_r_%ncsd.dnet From: diederich_r_%ncsd.dnet@GTE.COM (Ray Diederich (301)-294-8400) Newsgroups: comp.lang.ada Subject: RE: Exceptions vs. if-then-else Message-ID: <9103211807.AA22650@bunny.gte.com> Date: 21 Mar 91 18:07:13 GMT Sender: usenet@ucbvax.BERKELEY.EDU Organization: The Internet List-Id: In article 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. ========================================