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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a415d3a613d86a4e X-Google-Attributes: gid103376,public From: kst@king.cts.com (Keith Thompson) Subject: Re: Ada Enumerations Date: 1997/12/07 Message-ID: <881531533.459982@wagasa.cts.com>#1/1 X-Deja-AN: 296092676 Cache-Post-Path: wagasa.cts.com!kst@king.cts.com References: <662cs9$b34$1@newman.pcisys.net> <663j9f$e1l@mtinsc02.worldnet.att.net> <3485D2AE.3F54@hso.link.com> <3487293E.794B@hso.link.com> Organization: CTS Network Services Newsgroups: comp.lang.ada Date: 1997-12-07T00:00:00+00:00 List-Id: Stanley R. Allen (s_allen@hso.link.com) wrote: > Matthew Heaney wrote: > > Personally, I feel that if you're always looking at the rep of the > > enumerands, then you probably don't want an enumeration type anyway. > > That's a dead argument on the face of it. If the language > permits me to *specify* the representation, then why doesn't > it permit me to *query* the specified values? Because, IMHO, enumeration representation clauses weren't thought out as well as they should have been when Ada 83 was designed, and the problems weren't corrected in the Ada 95 revision. If the language had defined attributes to convert between an enumeration type and Universal_Integer, analogous to 'Val and 'Pos but using the underlying representation rather than the position value, along with a good way to determine whether an enumeration value from an external source is valid, enumeration representation clauses would have been much more useful. There are some partial solutions for these problems. Unchecked_Conversion can be used to query the representation; the problem is determining an integer type that matches a given enumeration type, especially if the representation includes negative values. GNAT provides the 'Enum_Rep attribute (but not 'Enum_Val), but it's not portable. The 'Valid attribute should be usable to validate external data, but straightforward use of it is erroneous by RM95-13.9.1; see also AI95-00167.