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: "Stanley R. Allen" Subject: Re: Ada Enumerations Date: 1997/12/03 Message-ID: <3485D2AE.3F54@hso.link.com>#1/1 X-Deja-AN: 294972570 References: <662cs9$b34$1@newman.pcisys.net> <663j9f$e1l@mtinsc02.worldnet.att.net> Organization: NASA, Kennedy Space Center Newsgroups: comp.lang.ada Date: 1997-12-03T00:00:00+00:00 List-Id: 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 'Size. -- Stanley Allen mailto:s_allen@hso.link.com