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: 1 Sep 93 15:47:15 GMT From: butch!rapnet!lvonrude@uunet.uu.net (Lowell S. VonRuden x5294) Subject: Unchecked_Conversion question Message-ID: <1993Sep1.154715.10498@Rapnet.Sanders.Lockheed.Com> List-Id: I am doing something that seems to work using a Verdix compiler, but I have not been able to determine if this is something that will be safely transportable. Hopefully, someone here can tell me. I have a 32 bit value coming in from an external interface as an integer, which I am mapping to an enumeration type. The enumeration type has representation clauses for both size (Integer'Size) and implementation values. Assigning the result of an unchecked conversion from the integer to an object of the enumeration type doesn't raise any exception if the integer is out of range for the enumeration type representation. I found that if I do an explicit conversion of the enumeration object to its type, then the range gets checked. procedure Sample (Int : Integer) is type Enum is (AAA, BBB, CCC, DDD); for Enum use (AAA=> 1, BBB=> 2, CCC=> 13, DDD=> 14); for Enum'Size use Integer'Size; function Convert is new Unchecked_Conversion (Source => Integer, Target => Enum); begin E := Convert (Int); -- no exception raised here if Int is out of range E := Enum (Convert (Int)); -- this does raise constraint error if -- Int is out of range end Sample; So, is this a dependable thing to do? -- -------------------------------------------------------------------- -- Usual disclaimers apply... Lowell Von Ruden -- -- lvonrude@rapnet.sanders.lockheed.com Lockheed Sanders, Inc -- --------------------------------------------------------------------