comp.lang.ada
 help / color / mirror / Atom feed
From: "Martin Dowie" <martin.dowie@btopenworld.com>
Subject: Re: Enum or Named Number
Date: Tue, 6 Apr 2004 17:49:38 +0000 (UTC)
Date: 2004-04-06T17:49:38+00:00	[thread overview]
Message-ID: <c4uqji$b5h$1@titan.btinternet.com> (raw)
In-Reply-To: fe4bb2c2.0404060930.f932668@posting.google.com

"Jeff" <jeff.huter@bigfoot.com> wrote in message
news:fe4bb2c2.0404060930.f932668@posting.google.com...
> Looking for implementation advise.  I'm writing a binding to some C
> code that has several defined number macros (e.g. #define Viewable 1)
> for states and flags.  I would like to bitwise-or these numbers in Ada
> which leads me to believe I should define these as named mod numbers
> such as below:
>
> type State is mod 2**Interfaces.C.Int'Size
> State1 : constant State := 2#0001#
> State2 : constant State := 2#0010#
> State3 : constant State := 2#0100#
>
> Any reason to define these as an Enum with a representation clause?
> Seems like there would be more plumbing code.  For example, I believe
> that I would need to write my own bitwise-or function for the Enum.
>
> Is the named number implementation the way to go, or is there a better
> way?

Depends on a couple of things:

1) are you trying to provide a thick or thin binding?
2) can the "states" really mutually exclusive or can they be 'set' at the
same time?

If the answer to 1) is "thick binding" and 2) is "really mutually exclusive"
then I would take the hit and declare an Ada enumeration and use a lookup
table to get the C representation.

Otherwise, I think I'd just stick with the above.

-- Martin






  reply	other threads:[~2004-04-06 17:49 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 [this message]
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
replies disabled

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