comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Ada Enumerations
Date: 1997/12/04
Date: 1997-12-04T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023680000412970252290001@news.ni.net> (raw)
In-Reply-To: 3485D2AE.3F54@hso.link.com


In article <3485D2AE.3F54@hso.link.com>, "Stanley R. Allen"
<s_allen@hso.link.com> wrote:

>> 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.

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
being said, why don't you just perform an instantiation of UC at the point
of declaration of the type?

with Unchecked_Conversion, Interfaces;
package Color_Types is

   type Color is (Red, Green, Blue);
   
   for Color use (Red => 2, Green => 5, Blue => 8);

   for Color'Size use 8;

   function To_Rep is
      new Unchecked_Conversion (Color, Interfaces.Unsigned_8);

end Color_Types;

What's the big deal?  It's only 1 extra declaration (the instantiation of UC).

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




  parent reply	other threads:[~1997-12-04  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
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
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       ` 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-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       ` Matthew Heaney [this message]
1997-12-04  0:00         ` Ada Enumerations Stanley R. Allen
1997-12-07  0:00           ` Keith Thompson
1997-12-07  0:00             ` Matthew Heaney
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-04  0:00 ` 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 ` John M. Mills
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
replies disabled

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