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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f70e7a457bf23e69 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-24 10:44:34 PST Path: nntp.gmd.de!news.rwth-aachen.de!news.rhrz.uni-bonn.de!news.uni-stuttgart.de!rz.uni-karlsruhe.de!xlink.net!howland.reston.ans.net!news.sprintlink.net!uunet!boulder!news.coop.net!news.den.mmc.com!iplmail.orl.mmc.com!usenet From: Theodore Dennison Newsgroups: comp.lang.ada Subject: Re: Optimizing and Constraint Checks Date: 24 Mar 1995 13:34:48 GMT Organization: IPL InterNetNews site Message-ID: <3kuhpo$ban@theopolis.orl.mmc.com> References: NNTP-Posting-Host: payday.orl.mmc.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit To: edward@igate1.hac.com X-URL: news:edward-2303951004270001@r-618macip27.hac.com Date: 1995-03-24T13:34:48+00:00 List-Id: Ed Bruce writes: > 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. Your engineer has a vaild concern. One of the problems with Ada 83 is that there is no PORTABLE way to force a constraint check. In practice, you have to find what your compiler won't optimize away, and code to that. Unfortunately, the next version of the same compiler could work differently. In practice this isn't as big a problem as it looks on paper. I have only encountered one compiler (for an embedded system) which optimized away too many checks. The benefits that this kind of type checking can give you vastly outweigh the problems it causes. Just make sure you test it! Hopefully, this problem was fixed with Ada 95. T.E.D.