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,45a9122ddf5fcf5 X-Google-Attributes: gid103376,public From: kst@thomsoft.com (Keith Thompson) Subject: Re: Valid Attribute and Unchecked Conversion Date: 1996/10/09 Message-ID: #1/1 X-Deja-AN: 188356012 sender: news@thomsoft.com (USENET News Admin @flash) x-nntp-posting-host: pulsar references: organization: Thomson Software Products, San Diego, CA, USA newsgroups: comp.lang.ada originator: kst@pulsar Date: 1996-10-09T00:00:00+00:00 List-Id: In dewar@schonberg.cs.nyu.edu (Robert Dewar) writes: > Keith says > > "For example, the language could have defined two additional attributes, > analagous to 'Pos and 'Val, but operating on the internal representation > of an enumeration type. If the argument is an invalid representation, > simply raise Constraint_Error. GNAT provides half of this with its > 'Enum_Rep attribute." > > The intention in Ada 95 is that both operations are achievbable using > unchecked conversion. It is a bug in the RM if this is not the case. Ok, but unchecked conversion to what? Since you can't get at the underlying representation values as static expressions, there's no portable way (that I know of) to declare an integer type of the same size as an arbitrary enumeration type. If I could write type Int_Type is range Enum_Type'Blorch(Enum_Type'First) .. Enum_Type'Blorch(Enum_Type'Last); (where 'Blorch is the non-existent attribute that returns the internal code for an enumeration value), I could safely do unchecked conversions between Int_Type and Enum_Type (if I ignore 13.9.1(12)). Something like this is *probably* close enough: type Enum_Type is (...); for Enum_Type use (...); type Int_Type is range 0 .. 2**Enum_Type'Size-1; -- OR type Int_Type is mod 2**Enum_Type'Size; for Int_Type'Size use Enum_Type'Size; -- superfluous? function To_Int is new Ada.Unchecked_Conversion(Enum_Type, Int_Type); function To_Enum is new Ada.Unchecked_Conversion(Int_Type, Enum_Type); but it won't quite work if some of the enumeration codes are negative. > However, in practice, of coruse this works, no matter what it says in > the RM, so this point can be left moot without having any pragmatic > effect. Moot in both senses of the word! 8-)} I don't agree that there's no pragmatic effect. The effect is not on implementers, but on users. Even if all implementations happen to behave "sensibly" in this area, a careful user trying to write portable code will avoid anything that the RM says is erroneous. I think we need a binding interpretatin saying something like "When we said 'erroneous' in 13.9.1(12), we were only kidding. Yeah, there's the ticket!" 8-)} 8-)} -- Keith Thompson (The_Other_Keith) kst@thomsoft.com <*> TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products 10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2706 FIJAGDWOL