From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Need Value of enum type not position.
Date: Fri, 07 Nov 2003 14:26:46 -0500
Date: 2003-11-07T14:26:46-05:00 [thread overview]
Message-ID: <5sWdnUsWT9tqbDaiRVn-uw@comcast.com> (raw)
In-Reply-To: <686be06c.0311071027.79d6fa21@posting.google.com>
Daniel Allex wrote:
> With the following declaration:
>
> type Hov_Mode_Type is
> (INVALID,
> OFF,
> INITIATE,
> AUTO);
> for Hov_Mode_Type use(
> INVALID => 7,
> OFF => 8,
> INITIATE => 9,
> AUTO => 10);
>
> I can get the position
> 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.
The ability to specify representations for enumeration types changes how
the values are represented in hardware. The function 'Pos returns the
position number, not the representation. If you want the
representation, add also a 'Size clause, then do an Unchecked_Conversion
to an appropriate integer type.
For this particular case you could just declare a type with eleven
values, and derive from it:
type Hov_Base_Type is (HovO, Hov1, Hov2, Hov3, Hov4, Hov5, Hov6,
Invalid, Off, Initiate, Auto);
type Hov_Mode_Type is new Hov_Base_Type range Invalid..Auto;
--
Robert I. Eachus
100% Ada, no bugs--the only way to create software.
next prev parent reply other threads:[~2003-11-07 19:26 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 [this message]
2003-11-08 0:16 ` Nick Roberts
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