comp.lang.ada
 help / color / mirror / Atom feed
From: kst@thomsoft.com (Keith Thompson)
Subject: Re: Valid Attribute and Unchecked Conversion
Date: 1996/10/09
Date: 1996-10-09T00:00:00+00:00	[thread overview]
Message-ID: <DyzxJ9.Brn@thomsoft.com> (raw)
In-Reply-To: dewar.844696412@schonberg


In <dewar.844696412@schonberg> 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




  reply	other threads:[~1996-10-09  0:00 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-22  0:00 Rules for Representation of Subtypes Matthew Heaney
1996-09-23  0:00 ` Robert A Duff
1996-09-24  0:00   ` Matthew Heaney
1996-09-26  0:00     ` Robert A Duff
1996-09-26  0:00       ` Larry Kilgallen
1996-09-27  0:00         ` Robert A Duff
1996-09-27  0:00           ` Mark A Biggar
1996-09-30  0:00             ` Robert A Duff
1996-10-01  0:00               ` Larry Kilgallen
1996-10-01  0:00                 ` Samuel Tardieu
1996-10-01  0:00                   ` Valid Attribute and Unchecked Conversion Matthew Heaney
1996-10-02  0:00                     ` Robert A Duff
1996-10-04  0:00                       ` Keith Thompson
1996-10-04  0:00                         ` Robert A Duff
1996-10-04  0:00                           ` Robert Dewar
1996-10-11  0:00                             ` Norman H. Cohen
1996-10-12  0:00                               ` Robert Dewar
1996-10-06  0:00                           ` Keith Thompson
1996-10-07  0:00                             ` Robert Dewar
1996-10-09  0:00                               ` Keith Thompson [this message]
1996-10-07  0:00                           ` Ken Garlington
1996-10-08  0:00                           ` Alan Brain
1996-10-04  0:00                         ` Matthew Heaney
1996-10-07  0:00                           ` Robert Dewar
1996-10-09  0:00                             ` Keith Thompson
1996-10-07  0:00                         ` Robert Dewar
1996-10-10  0:00                           ` Ken Garlington
1996-10-11  0:00                             ` Robert Dewar
1996-10-14  0:00                               ` Keith Thompson
1996-10-14  0:00                               ` Ken Garlington
1996-10-07  0:00                         ` Kenneth Almquist
1996-10-01  0:00                   ` Rules for Representation of Subtypes Ken Garlington
1996-10-01  0:00                 ` Robert A Duff
1996-09-28  0:00           ` Larry Kilgallen
1996-09-29  0:00             ` Robert A Duff
1996-09-29  0:00               ` Matthew Heaney
1996-09-30  0:00                 ` Robert Dewar
1996-09-30  0:00                   ` Matthew Heaney
1996-09-30  0:00                 ` Robert A Duff
1996-09-29  0:00               ` Larry Kilgallen
1996-09-29  0:00                 ` Matthew Heaney
1996-09-30  0:00                 ` Robert A Duff
1996-10-01  0:00                   ` Ken Garlington
1996-10-02  0:00                     ` Robert A Duff
1996-10-02  0:00                       ` Ken Garlington
1996-10-06  0:00                   ` Robert Dewar
1996-10-03  0:00             ` Robert Dewar
1996-10-02  0:00         ` Valid Attribute and Unchecked Conversion George Haddad
1996-10-03  0:00           ` John Herro
1996-10-04  0:00             ` Karl Cooper {46901}
1996-10-07  0:00               ` Mark A Biggar
1996-10-08  0:00                 ` Robert Dewar
1996-10-05  0:00             ` Robert Dewar
1996-10-06  0:00               ` Keith Thompson
1996-10-14  0:00                 ` Robert A Duff
1996-10-02  0:00         ` Robert I. Eachus
1996-10-02  0:00           ` Matthew Heaney
1996-09-27  0:00       ` Rules for Representation of Subtypes Matthew Heaney
1996-09-27  0:00         ` Robert A Duff
1996-09-23  0:00 ` David C. Hoos, Sr.
1996-09-23  0:00   ` Samuel T. Harris
1996-09-26  0:00     ` David C. Hoos, Sr.
1996-09-23  0:00   ` Robert A Duff
1996-09-24  0:00   ` Robert Dewar
1996-09-24  0:00   ` Robert Dewar
1996-09-26  0:00     ` Keith Thompson
1996-09-26  0:00       ` Matthew Heaney
1996-09-27  0:00         ` Robert Dewar
1996-09-27  0:00         ` Robert A Duff
1996-09-27  0:00           ` Robert Dewar
1996-09-27  0:00       ` Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
1996-10-03  0:00 Valid Attribute and Unchecked Conversion Franco Mazzanti
1996-10-04  0:00 Franco Mazzanti
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox