From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 3 Sep 93 19:51:51 GMT From: dog.ee.lbl.gov!agate!howland.reston.ans.net!spool.mu.edu!sdd.hp.com!netwo rk.ucsd.edu!news.cerf.net!shrike.irvine.com!adam@ucbvax.Berkeley.EDU (Adam Ben eschan) Subject: Re: Unchecked_Conversion question Message-ID: List-Id: In article <2684k7$2hc@sun_tzu.sp.paramax.com> parkhill@sun_tzu.sp.paramax.com (Robert Parkhill) writes: > adam@irvine.com (Adam Beneschan) writes: > > In article <1993Sep1.154715.10498@Rapnet.Sanders.Lockheed.Com> lvonrude@R apnet.Sanders.Lockheed.Com (Lowell S. VonRuden x5294) writes: > > > > Anyway, if you want a more dependable version, try this: > > > -- Deleted text > > > > if Int not in Enum_Low .. Enum_High then > > raise Constraint_Error; -- or whatever > > end if; > > E := Convert (Int); > > > > end Sample; > > > I would not count on this being dependable, please refer to Tucker > Taft's post. I can tell you that people I have worked with tried > this with the TeleSoft Ada compiler and found there code optimized > away. The compiler assumed that anything it does is correct and > therefore it need not check for things that are obviously true. ;) > > To it asking whether an enum was between the first legal value > and the last legal value was like asking if an integer object > had a value between integer'First and integer'Last. The answer > was always yes. Yes, that was my point exactly. Which is why I DIDN'T ask whether an enumeration was between the first legal value and the last legal value. In my example above, Int is still an integer; it hasn't been converted to an enumeration yet. My point, and Tucker's also, was that the checking should be done on the *integer* before it's converted. -- Adam