comp.lang.ada
 help / color / mirror / Atom feed
From: AdaMagica <christ-usch.grein@t-online.de>
Subject: Re: Problem with Position of the enumeration Type
Date: Thu, 24 Jan 2019 00:06:49 -0800 (PST)
Date: 2019-01-24T00:06:49-08:00	[thread overview]
Message-ID: <959429b8-2817-4339-bd01-01153a7a544c@googlegroups.com> (raw)
In-Reply-To: <217206e7-81aa-4aa8-8d19-66498c36100d@googlegroups.com>

Am Mittwoch, 23. Januar 2019 13:08:34 UTC+1 schrieb Luis Ladron de Guevara Moreno:
> El miércoles, 23 de enero de 2019, 11:33:36 (UTC+1), AdaMagica  escribió:
> > See RM 13.4(11/3)ff:
> > NOTES
> > 14 Unchecked_Conversion may be used to query the internal codes used for
> > an enumeration type. The attributes of the type, such as Succ, Pred, and Pos, are unaffected by the enumeration_representation_clauserepresentation_clause.
> > 
> > Some questions on your code:
> > 
> >   Position : Integer;  -- Why is this Integer and not Natural?
> >    
> >   for I in E_Test'Base loop  -- Why do you use 'Base here?
> 
> I wrote a Integer as an example, i could add Natural also, for this example there are not difference.

It does make a difference. Ada has subtypes just for this purpose: If you know that the values of an object of some type belong only to some subtype, you indicate this in the declaration.
This is the very idea of stong typing.

> I'm using 'Range to go through all the positions in enumeration.

No, you used 'Base.

For a enum type E, these are always the same:

for V in E loop
for V in E'Range loop

For an enum type that is not derived, E'Base is the same as E. For types derived from E, there might be a difference.

> I tried to use Ada.Unchecked_Conversion and i got obtain the values for the position. but as you told me, if i use 'post (), the number of the list start in 0.

Yes, this is what the RM prescribes.

  parent reply	other threads:[~2019-01-24  8:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-23 10:05 Problem with Position of the enumeration Type Luis Ladron de Guevara Moreno
2019-01-23 10:33 ` AdaMagica
2019-01-23 10:55   ` AdaMagica
2019-01-23 12:08   ` Luis Ladron de Guevara Moreno
2019-01-23 12:15     ` Karl Müller
2019-01-23 21:50     ` Niklas Holsti
2019-01-24  8:06     ` AdaMagica [this message]
2019-01-23 11:32 ` Mark Lorenzen
2019-01-23 12:30   ` Luis Ladron de Guevara Moreno
2019-01-23 20:22     ` Shark8
2019-01-24  8:13       ` AdaMagica
2019-01-23 17:06 ` Simon Wright
2019-01-23 22:54   ` Randy Brukardt
2019-01-23 23:47     ` Keith Thompson
2019-01-24  4:34       ` Keith Thompson
2019-01-24  9:11         ` Simon Wright
2019-01-24 21:41       ` Randy Brukardt
2019-01-23 21:42 ` Niklas Holsti
2019-01-23 22:35   ` Simon Wright
2019-01-23 23:20     ` Niklas Holsti
2019-01-24 16:43     ` Jeffrey R. Carter
2019-01-24 19:39       ` Niklas Holsti
2019-01-24 20:29         ` Jeffrey R. Carter
2019-01-24 21:43         ` Randy Brukardt
2019-01-26  9:44   ` G.B.
replies disabled

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