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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f70e7a457bf23e69,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-23 08:04:27 PST Path: nntp.gmd.de!stern.fokus.gmd.de!ceres.fokus.gmd.de!zib-berlin.de!Germany.EU.net!EU.net!news.sprintlink.net!cs.utexas.edu!uwm.edu!fnnews.fnal.gov!nntp-server.caltech.edu!news.cerf.net!hacgate2.hac.com!r-618macip27.hac.com!user From: edward@igate1.hac.com (Ed Bruce) Newsgroups: comp.lang.ada Subject: Optimizing and Constraint Checks Date: Thu, 23 Mar 1995 10:04:27 -0600 Organization: Hughes Aircraft Message-ID: Reply-To: edward@igate1.hac.com NNTP-Posting-Host: r-618macip27.hac.com Keywords: unchecked_conversion, optimize, constraints Date: 1995-03-23T10:04:27-06:00 List-Id: I am currently attempting to implement a safe, portable Unchecked_Conversion of an enumerated type to integer and from an integer type back to the enumeration. The following code shows the current solution, the question raised by one engineer is can we guarantee the the return statement in the To_Enum function is portable. That is may a compiler optimize away the ENUM'Pos and ENUM'Val and effectively eliminate the constraint check. with Unchecked_Conversion; generic type ENUM is (<>); package Convert is Illegal_Value : exception; function To_Integer( Value : in ENUM ) return INTEGER; function To_Enum ( Value : in INTEGER ) return ENUM; end Convert; package Convert is function To_Integer is new Unchecked_Conversion( Source => ENUM, Target => INTEGER ); function Convert_Enum is new Unchecked_Conversion( Source => INTEGER, Target => ENUM ); function To_Enum( Value : in INTEGER ) return ENUM is begin return ENUM'Val( ENUM'Pos( Convert_Enum( Value ))) exception when Constraint_Error => raise Illegal_Value; when Others => raise; end To_Enum; end Convert; Ed Bruce edward@igate1.hac.com