comp.lang.ada
 help / color / mirror / Atom feed
From: Nick Roberts <nick.roberts@acm.org>
Subject: Re: Need Value of enum type not position.
Date: Sat, 08 Nov 2003 00:16:42 +0000
Date: 2003-11-08T00:16:42+00:00	[thread overview]
Message-ID: <bohclh$1dlr3h$1@ID-25716.news.uni-berlin.de> (raw)
In-Reply-To: <5sWdnUsWT9tqbDaiRVn-uw@comcast.com>

A possible alternative approach, not necessarily any better than using 
Unchecked_Conversion, is to use a constant lookup array:

    type Hov_Mode_Type is
          (INVALID,
           OFF,
           INITIATE,
           AUTO);

    Hov_Mode_Code: constant array (Hov_Mode_Type) of Integer :=
          (INVALID  => 7,
           OFF      => 8,
           INITIATE => 9,
           AUTO     => 10);

Depending on other factors (you have not mentioned), it may or may not be 
necessary for you to also have the enumeration representation clause.

One advantage of this technique is that it may make the logic of a certain 
part of your code immune to changes in representation (encoding) which 
might perhaps be required during the maintenance or update of another part 
of your code (or hardware). Obviously, this separation could turn out to be 
a disadvantage, depending on the logic of your code.

A disadvantage is that the lookup array is likely (but not certain) to be 
implemented as an actual array in memory. If the speed of obtaining a code 
is critical, this might matter (but I think it's unlikely). This sort of 
array can have cache-clobbering properties, which can be unfortunate from a 
speed point of view (but not in any other way).

-- 
Nick Roberts




  reply	other threads:[~2003-11-08  0:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-07 18:27 Need Value of enum type not position Daniel Allex
2003-11-07 19:26 ` Robert I. Eachus
2003-11-08  0:16   ` Nick Roberts [this message]
2003-11-10 13:48 ` Mark Doherty
2003-11-10 18:04 ` Marius Amado Alves
  -- strict thread matches above, loose matches on Subject: below --
2003-11-10 17:30 Beard, Frank Randolph CIV
2003-11-18 21:07 ` Randy Brukardt
2003-11-10 18:25 Beard, Frank Randolph CIV
replies disabled

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