From: "Marc A. Criley" <mcqada@earthlink.net>
Subject: Re: enumration using integers?
Date: Thu, 19 Apr 2001 12:42:19 GMT
Date: 2001-04-19T12:42:19+00:00 [thread overview]
Message-ID: <3ADECFD9.CBC57268@earthlink.net> (raw)
In-Reply-To: 3ADEC4E8.954B6830@emw.ericsson.se
Sven Nilsson wrote:
>
> Hello
>
> I have a little problem that I don't want to spend time solving...
>
> If I want to make an enumerated type using integers, like:
>
> type Distance is (10, 20, 30, 40, 50);
>
> The compiler will complain about missing identifiers. How do I get the
> blasted machine to understand that the integers are the identifiers I
> want?
>
Well, integers are not identifiers, and enumeration literals must be
identifiers, so you cannot create an enumeration type whose literals are
integers.
Given a type definition like:
type Distance is (Km_10, Km_20, Km_30, Km_40, Km_50);
If you're using values of that type in registers or particular memory
locations, as is commonly done in embedded programming, you can
associate a representation specification with the type:
for Distance use (Km_10 => 10, Km_20 => 20, Km_30 => 30,
Km_40 => 40, Km_50 => 50);
Or you can just use a little lookup table to get the value:
type Distance_Values is array (Distance) of Natural;
Dist : constant Distance_Values :=
(Km_10 => 10, Km_20 => 20, Km_30 => 30,
Km_40 => 40, Km_50 => 50);
Then just look up the value through the table:
for D in Distance'Range loop
Process(Dist(D));
end loop;
Marc A. Criley
Senior Staff Engineer
Quadrus Corporation
www.quadruscorp.com
next prev parent reply other threads:[~2001-04-19 12:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-04-19 10:58 enumration using integers? Sven Nilsson
2001-04-19 12:42 ` Marc A. Criley [this message]
2001-04-19 13:02 ` Philip Anderson
2001-04-19 14:50 ` Ted Dennison
2001-04-20 5:22 ` Sven Nilsson
2001-04-20 13:57 ` Ted Dennison
2001-04-20 14:35 ` Sven Nilsson
2001-04-20 15:50 ` Keith Thompson
2001-04-20 18:18 ` Ted Dennison
2001-04-20 15:52 ` Samuel T. Harris
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox