comp.lang.ada
 help / color / mirror / Atom feed
From: "Stanley R. Allen" <s_allen@hso.link.com>
Subject: Re: Ada Enumerations
Date: 1997/12/03
Date: 1997-12-03T00:00:00+00:00	[thread overview]
Message-ID: <3485D2AE.3F54@hso.link.com> (raw)
In-Reply-To: dewar.881162762@merv


Robert Dewar wrote:
> 
> Jim Rogers said
> 
> you must instantiate Ada.Unchecked_Conversion. for your enumeration
> type.
> >>
> 
> If you are using GNAT, you can use the 'Enum_Rep attribute to get the
> representation value for an enumeration literal. This seems a generally
> useful attribute, it would be nice if other Ada 95 compilers would
> implement it.
> 

Hear, Hear!  I was surprised that Ada95 didn't correct this obvious
deficiency in Ada83.  I've been frustrated with the unchecked_conversion
approach for quite a while.  Here is the problem:

    type Value_List_Type is array (Natural range <>) of Integer;
    generic
        type Enum is (<>);
    function Value_List return Value_List_Type;

If the function Value_List is to allow instantiation of any enumeration
type, the size (in bits) of the actual type must be taken into account
if Unchecked_Conversion is used.  And this is very ugly.  With the
'Enum_Rep clause, it's easy to do this:

    function Value_List return Value_List_Type is
        Tmp : Value_List_Type (Enum'Pos (Enum'First) ..
                               Enum'Pos (Enum'Last));
    begin
        for I in Tmp'Range loop
            Tmp (I) := Enum'Enum_Rep (Enum'Val (I));
        end loop;
        return Tmp;
    end Value_List;

The functionality of the clause is worth the trade-off of the ugly
name.  Most of the ACT-chosen names for implementation-defined
attributes are depressing (e.g., 'Img, 'Elab_Spec -- ugh.)

While we are on the subject, it would be nice if the GNAT-defined
'Object_Size (a better name than the equivalent DEC-Ada-defined
'Machine_Size) attribute was universally adopted as well.  Those
of us who must work at the bit level get frustrated when we cannot
get at the actual number of bits that will be allocated for an
entity, rather than the "minumum" given by <type>'Size.

-- 
Stanley Allen
mailto:s_allen@hso.link.com




  reply	other threads:[~1997-12-03  0:00 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-03  0:00 Ada Enumerations Jeffrey Harris
1997-12-03  0:00 ` James S. Rogers
1997-12-03  0:00   ` Robert Dewar
1997-12-03  0:00     ` Stanley R. Allen [this message]
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-04  0:00       ` Ada Enumerations Robert Dewar
1997-12-04  0:00         ` Stanley R. Allen
1997-12-18  0:00           ` Wes Groleau
1997-12-04  0:00       ` Matthew Heaney
1997-12-04  0:00         ` Stanley R. Allen
1997-12-07  0:00           ` Keith Thompson
1997-12-07  0:00             ` Robert Dewar
1997-12-08  0:00               ` Keith Thompson
1997-12-07  0:00                 ` Matthew Heaney
1997-12-11  0:00                   ` John G. Volan
1997-12-07  0:00             ` Matthew Heaney
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-05  0:00         ` GNAT'Object_Size Mats Weber
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-08  0:00         ` GNAT'Object_Size Mats Weber
1997-12-10  0:00           ` GNAT'Object_Size Robert Dewar
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-04  0:00 ` Ada Enumerations Stephen Leake
1997-12-04  0:00   ` Matthew Heaney
1997-12-04  0:00     ` Robert Dewar
1997-12-06  0:00       ` Jean-Pierre Rosen
1997-12-06  0:00         ` Making Predefined Operators Abstract Matthew Heaney
  -- strict thread matches above, loose matches on Subject: below --
1997-12-10  0:00 Ada enumerations Stanley R. Allen
1997-12-10  0:00 ` Robert Dewar
1997-12-11  0:00   ` Mats Weber
1997-12-11  0:00     ` Robert Dewar
1997-12-12  0:00       ` Mats Weber
1997-12-12  0:00         ` Robert Dewar
1997-12-12  0:00     ` Samuel T. Harris
1997-12-11  0:00   ` Stanley R. Allen
1997-12-12  0:00     ` Robert Dewar
1997-12-10  0:00 ` John M. Mills
replies disabled

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