comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@acm.org>
To: comp.lang.ada@ada-france.org
Cc: David Botton <david@botton.com>
Subject: Re: A question re meaning/use of the "for ... use ..."
Date: 05 Dec 2004 10:59:03 -0500
Date: 2004-12-05T10:59:03-05:00	[thread overview]
Message-ID: <mailman.173.1102262931.10401.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <41b3291e$0$44072$5fc3050@dreader2.news.tiscali.nl>

Erik J Pessers <epessers@tiscali.be> writes:

> Hi,
> 
> A question re meaning/use of the "for ... use ..." construct.
> 
> Given the code snippet at the bottom of this mail, I was sort of
> expecting to see an output reading like:
> 
> 	Pos for AA : 0
> 	Pos for BB : 2
> 	Pos for CC : 3
> 
> 
> 
> Instead (when compiling with bot Gnat3.15p and Gnat-3.4.2-2),
> the actual code output reads:
> 
> 	Pos for AA : 0
> 	Pos for BB : 1
> 	Pos for CC : 2

This is definitely a FAQ, but I don't see it at AdaPower. David; the
Ada FAQ says it is maintained by the users, but I don't see any way to
submit new FAQs. Please consider this a submission.

The enumeration representation clause (see ARM 13.4) specifies the
internal representation of an enumeral. The 'Pos attribute (see ARM
Annex K) returns the position number of an enumeral. 

Position numbers start at 0 and increment by one for each enumeral.

There is no standard attribute that returns the internal
representation specified by the enumeration representation clause.
However, GNAT provides the non-standard 'Enum_Rep for this purpose.

> Anybody who can shed some light, and explain what will be going on
> behind the curtains?

Typical reasons for specifying an enum rep clause are for interfacing
to another language, or for interfacing to hardware. In both cases,
the value to be passed is specified by the external object, and the
Ada code must match it. So for your type:

>       type enm is (aa, bb, cc) ;
>       for enm use
>       	(aa     => 0,
>        	bb     => 2,
>        	cc     => 3);

if you pass "bb" to a C program, it will get the value 2.

-- 
-- Stephe




  parent reply	other threads:[~2004-12-05 15:59 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-05 15:27 A question re meaning/use of the "for ... use ..." Erik J Pessers
2004-12-05 15:47 ` Martin Krischik
2004-12-05 15:59 ` Stephen Leake [this message]
2004-12-05 16:52   ` Jeffrey Carter
2004-12-06 19:59     ` Randy Brukardt
2004-12-07  1:36       ` Jeffrey Carter
2004-12-07  2:40         ` David C. Hoos, Sr.
2004-12-07 20:59         ` Randy Brukardt
2004-12-08  1:41           ` Jeffrey Carter
2004-12-08  8:40           ` Martin Dowie
2004-12-08 16:23             ` Georg Bauhaus
2004-12-08  3:18       ` Keith Thompson
2004-12-08 13:48         ` David C. Hoos
2004-12-08 19:50         ` Randy Brukardt
2004-12-08 23:00           ` Keith Thompson
2004-12-09 23:06             ` Randy Brukardt
2004-12-10  2:26               ` Keith Thompson
2004-12-10 19:42                 ` Randy Brukardt
2004-12-10 21:18                   ` Keith Thompson
2004-12-11  0:53                     ` Keith Thompson
2004-12-10  3:13             ` David C. Hoos
2004-12-10  9:23               ` Keith Thompson
2004-12-10 13:24                 ` David C. Hoos
replies disabled

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