comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Enum or Named Number
Date: Tue, 13 Apr 2004 09:29:58 -0400
Date: 2004-04-13T09:29:58-04:00	[thread overview]
Message-ID: <G8KdnQT7srvFdubdRVn-vw@comcast.com> (raw)
In-Reply-To: <fe4bb2c2.0404060930.f932668@posting.google.com>

Jeff wrote:

> Is the named number implementation the way to go, or is there a better
> way?

It may be, but there is a third way that is often right for such types. 
  You define an enumeration type:

type State_Index is (...State3_Index, State2_Index, State1_Index);

(You may not need to reverse the order to match the C code, but it is 
the more common way of defining such types in C.  And in that case it is 
much easier to have exactly 16 or 32--or whatever word size is--values.) 
Now you define your state type:

type State is array (State_Index) of Boolean;

And now you can define any subsets you need:

State3: State := (State3_Index => True, others => False);

This approach is very wordy in the defining package. (But what is cut 
and paste for?)  It does give you an abstraction with the various 
(mathematical) set operations defined but no arithmetic operations.  Of 
course, another way to do that is to make the type private and export 
only the operations you want.


-- 

                                           Robert I. Eachus

"The terrorist enemy holds no territory, defends no population, is 
unconstrained by rules of warfare, and respects no law of morality. Such 
an enemy cannot be deterred, contained, appeased or negotiated with. It 
can only be destroyed--and that, ladies and gentlemen, is the business 
at hand."  -- Dick Cheney




      parent reply	other threads:[~2004-04-13 13:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-06 17:30 Enum or Named Number Jeff
2004-04-06 17:49 ` Martin Dowie
2004-04-06 19:22   ` Randy Brukardt
2004-04-07  7:23     ` Martin Dowie
2004-04-07  9:34 ` Dmitry A. Kazakov
2004-04-13 13:29 ` Robert I. Eachus [this message]
replies disabled

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