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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b1a96e8174ef9f99 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-10 09:32:03 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.stueberl.de!teaser.fr!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: "Beard, Frank Randolph CIV" Newsgroups: comp.lang.ada Subject: RE: Need Value of enum type not position. Date: Mon, 10 Nov 2003 12:30:42 -0500 Organization: Cuivre, Argent, Or Message-ID: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: melchior.cuivre.fr.eu.org 1068485522 42684 80.67.180.195 (10 Nov 2003 17:32:02 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Mon, 10 Nov 2003 17:32:02 +0000 (UTC) To: Return-Path: X-MimeOLE: Produced By Microsoft Exchange V6.0.6375.0 Content-Class: urn:content-classes:message X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Need Value of enum type not position. Thread-Index: AcOnkZtbWMp9voLyQpuC2ybDDt8rqwAGpRYQ X-OriginalArrivalTime: 10 Nov 2003 17:31:13.0785 (UTC) FILETIME=[705ECE90:01C3A7B0] X-Virus-Scanned: by amavisd-new-20030616-p5 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Gateway to the comp.lang.ada Usenet newsgroup List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: archiver1.google.com comp.lang.ada:2307 Date: 2003-11-10T12:30:42-05:00 I would still go with Unchecked_Conversion. The problem with a look-up table is it requires more maintenance. With the Unchecked_Conversion approach, you change or add to the type in one place, instead of having to mirror the change in your look-up table. That way you just have: Hov_Mode_Type_size : constant :=3D 8; --+ or appropriate size =20 type Hov_Mode_Type is (INVALID, OFF, INITIATE, AUTO); for Hov_Mode_Type'size use Hov_Mode_Type_size; for Hov_Mode_type use=20 (INVALID =3D> 7, OFF =3D> 8, INITIATE =3D> 9, AUTO =3D> 10); type Number_Type is range 1..2**Hov_Mode_Type'size-1; for Number_Type'size use Hov_Mode_Type'size; function To_Number is new Ada.Unchecked_Conversion(Hov_Mode_Type, Number_Type); ... Ada.Text_IO.Put_Line(Number_Type'Image(To_Number(I))); Just my $0.02 ;-) =20 Frank =20 -----Original Message----- From: Mark Doherty [mailto:mark_doherty@yahoo.co.uk] Sent: Monday, November 10, 2003 8:48 To: comp.lang.ada@ada-france.org Subject: Re: Need Value of enum type not position. dallex@erols.com (Daniel Allex) wrote in message = news:<686be06c.0311071027.79d6fa21@posting.google.com>... > With the following declaration: > =20 > type Hov_Mode_Type is=20 > (INVALID, =20 > OFF, =20 > INITIATE,=20 > AUTO);=20 > for Hov_Mode_Type use( > INVALID =3D> 7,=20 > OFF =3D> 8,=20 > INITIATE =3D> 9,=20 > AUTO =3D> 10); >=20 > I can get the position=20 > Ada.Text_IO.Put_Line(Integer'Image(Hov_Mode_Type'Pos(I))); > Which returns 0,1,2, or 3. What I want is the value of 7,8,9,10. I > can't get 'val to work. need some help. You can use a lookup table, unchecked_conversion or an address overlay. I would use lookups where you are not mapping directly to hardware, otherwise unchecked_conversion is safer (than address overlays) as is can do compile and runtime checks. Use address overlays where performance in important. =20 [snip]