comp.lang.ada
 help / color / mirror / Atom feed
* Number of possible values in of enumerated type
@ 2009-06-08 20:52 Gautier
  2009-06-08 21:45 ` Jeffrey R. Carter
  0 siblings, 1 reply; 2+ messages in thread
From: Gautier @ 2009-06-08 20:52 UTC (permalink / raw)


Hello,
Did I overlook a specific attribute, or do I always need to write:

   Blah'Pos(Blah'Last)+1

for getting the number of possible values of an enumerated type ?
TIA
_________________________________________________________
Gautier's Ada programming -- http://sf.net/users/gdemont/
NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Number of possible values in of enumerated type
  2009-06-08 20:52 Number of possible values in of enumerated type Gautier
@ 2009-06-08 21:45 ` Jeffrey R. Carter
  0 siblings, 0 replies; 2+ messages in thread
From: Jeffrey R. Carter @ 2009-06-08 21:45 UTC (permalink / raw)


Gautier wrote:
>
> Did I overlook a specific attribute, or do I always need to write:
> 
>   Blah'Pos(Blah'Last)+1
> 
> for getting the number of possible values of an enumerated type ?

You didn't overlook anything. Note, however, that your solution fails for some 
constrained subtypes:

type E is (A, B, C);
subtype F is E range B .. C;

F'Pos (F'Last) = E'Pos (E'Last) = 2, so F'Pos (F'Last) + 1 gives 3, which is a 
problem if you want the number of values in subtype F (2). The general solution is

S'Pos (S'Last) - S'Pos (S'First) + 1

-- 
Jeff Carter
"Now look, Col. Batguano, if that really is your name."
Dr. Strangelove
31



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-06-08 21:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-08 20:52 Number of possible values in of enumerated type Gautier
2009-06-08 21:45 ` Jeffrey R. Carter

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