comp.lang.ada
 help / color / mirror / Atom feed
* Ada Enumerations
@ 1997-12-03  0:00 Jeffrey Harris
  1997-12-03  0:00 ` James S. Rogers
  1997-12-04  0:00 ` Stephen Leake
  0 siblings, 2 replies; 38+ messages in thread
From: Jeffrey Harris @ 1997-12-03  0:00 UTC (permalink / raw)



I have created an Ada Enumeration called DataTypes, afterwards I've created a
'use' clause where I give each element an integer value.  The last Enumeration
is LASTTYPE and is given a value of 100.

Now to the problem.  I'd like to be able to do something like the following..


NewLocation: Integer := DataTypes.LASTTYPE + 1;  -- Newlocation = 101

The compiler isn't letting me do this.  I've tried to use 'value, 'pos, and
'val to no avail, how do I convert an Ada enumerated type into an integer value?


Thanx... Please e-mail me at harris@pcisys.net

Jeff Harris




^ permalink raw reply	[flat|nested] 38+ messages in thread
* Re: Ada enumerations
@ 1997-12-10  0:00 Stanley R. Allen
  1997-12-10  0:00 ` Robert Dewar
  1997-12-10  0:00 ` John M. Mills
  0 siblings, 2 replies; 38+ messages in thread
From: Stanley R. Allen @ 1997-12-10  0:00 UTC (permalink / raw)



Matthew Heaney wrote:
> >
> >    function Value_List return Value_List_Type is
> >        Tmp : Value_List_Type (Enum'Pos (Enum'First) ..
> >                               Enum'Pos (Enum'Last));
> >    begin
> If you really insist on such a function, then do this:
> 
> generic
>    type Enum is (<>);
>    type Enum_Rep is range <>;
>    type Enum_Rep_Array is array (Natural range <>) of Enum_Rep;
> function Value_List return Value_List_Type;

This is certainly not a general solution.  Don't
forget: this is part of an interface to be used by
dozens of programmers on a large project with various
kinds of enumeration types.  It's too much of a burden
to make the users choose between two different generics
to instantiate depending on whether their enum type has
special representation or not.

> No, Ada doesn't come with an attribute to return the representation of an 
> enumeration literal, because it doesn't need to!

There are a number of features in Ada that you could
argue with on this basis.  Some of the features are
included for convenience (like 'Max), completeness, or
portability.  My argument for an attribute like
'Representation (or 'Enum_Rep in GNAT) is based on
these factors.  At the risk of seeming shrill, I'll
repeat myself: what good reason can there be for
allowing me to *specify* enumeration representations
but denying me the ability to easily *query* them also?

> And besides, if you're converting between enumeration literals and 
> integers often, you probably shouldn't be using an enumeration type 
> anyway.  Keep things simple, and use an integer type and associated 
> constants of that type.
> 

I would take too long in this forum to explain the
details, but note that working on a large project
often leaves you without the luxury of making that
choice.  In my case, I am not the one who decides
to "use an integer type and constants of that type"
instead of a rep-spec'd enumeration type.  The users
of my interface make that kind of decision as part
of their design process; it's my job to provide an
interface that's general enough to support them,
and simple enough to avoid complex programming on
their part.

-- 
Stanley Allen
mailto:s_allen@hso.link.com




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

end of thread, other threads:[~1997-12-18  0:00 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-12-03  0:00 Ada Enumerations Jeffrey Harris
1997-12-03  0:00 ` James S. Rogers
1997-12-03  0:00   ` Robert Dewar
1997-12-03  0:00     ` Stanley R. Allen
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-04  0:00       ` Ada Enumerations Matthew Heaney
1997-12-04  0:00         ` Stanley R. Allen
1997-12-07  0:00           ` Keith Thompson
1997-12-07  0:00             ` Matthew Heaney
1997-12-07  0:00             ` Robert Dewar
1997-12-08  0:00               ` Keith Thompson
1997-12-07  0:00                 ` Matthew Heaney
1997-12-11  0:00                   ` John G. Volan
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-05  0:00         ` GNAT'Object_Size Mats Weber
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-08  0:00         ` GNAT'Object_Size Mats Weber
1997-12-10  0:00           ` GNAT'Object_Size Robert Dewar
1997-12-04  0:00       ` GNAT'Object_Size Mats Weber
1997-12-04  0:00       ` Ada Enumerations Robert Dewar
1997-12-04  0:00         ` Stanley R. Allen
1997-12-18  0:00           ` Wes Groleau
1997-12-04  0:00 ` Stephen Leake
1997-12-04  0:00   ` Matthew Heaney
1997-12-04  0:00     ` Robert Dewar
1997-12-06  0:00       ` Jean-Pierre Rosen
1997-12-06  0:00         ` Making Predefined Operators Abstract Matthew Heaney
  -- strict thread matches above, loose matches on Subject: below --
1997-12-10  0:00 Ada enumerations Stanley R. Allen
1997-12-10  0:00 ` Robert Dewar
1997-12-11  0:00   ` Stanley R. Allen
1997-12-12  0:00     ` Robert Dewar
1997-12-11  0:00   ` Mats Weber
1997-12-11  0:00     ` Robert Dewar
1997-12-12  0:00       ` Mats Weber
1997-12-12  0:00         ` Robert Dewar
1997-12-12  0:00     ` Samuel T. Harris
1997-12-10  0:00 ` John M. Mills

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