From: Keith Thompson <kst@cts.com>
Subject: Re: Enumeration representation
Date: 1999/09/10
Date: 1999-09-10T00:00:00+00:00 [thread overview]
Message-ID: <yecn1uu9xy2.fsf@king.cts.com> (raw)
In-Reply-To: 37D8E3BC.175DB72C@newtech.it
Alex <busato@newtech.it> writes:
> I've written the following example program for testing enumeration
> represetantion clause:
[example deleted]
An enumeration representation clause is designed to change the
internal representation of an enumeration type *without* affecting the
visible semantics of the program. Thus, the 'Pos, 'Val, 'Image,
'Value, 'Succ, 'Pred attributes, etc., operate as if the enumeration
representation clause weren't there. The language doesn't define a
good way to get at the internal representation, though GNAT provides
an implementation-defined attribute for the purpose. (The usual
advice is to use Unchecked_Conversion; the trick is determining what
integer type, if any, is the same size and signedness as your
enumeration type.)
Of course, if you write a value of an enumeration type to an external
interface (a file, a serial line, a call to another language,
whatever), you'll get the internal representation. If you try to read
such a value from an external interface, it's very difficult to check
that you've gotten a valid value without invoking erroneous execution
(undefined behavior).
Basically, enumeration representation clauses are usually more trouble
than they're worth. It's usually better to just declare a collection
of integer constants. (Note: I said usually, not always.)
--
Keith Thompson (The_Other_Keith) kst@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
"Oh my gosh! You are SO ahead of your time!" -- anon.
next prev parent reply other threads:[~1999-09-10 0:00 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-09-10 0:00 Enumeration representation Alex
1999-09-10 0:00 ` David C. Hoos, Sr.
1999-09-10 0:00 ` Robert Dewar
1999-09-10 0:00 ` Keith Thompson [this message]
1999-09-11 0:00 ` Robert Dewar
1999-09-11 0:00 ` Keith Thompson
1999-09-12 0:00 ` Bryce Bardin
1999-09-13 0:00 ` Robert Dewar
1999-09-13 0:00 ` Keith Thompson
1999-09-13 0:00 ` Robert Dewar
1999-09-12 0:00 ` Keith Thompson
1999-09-13 0:00 ` Robert Dewar
1999-09-13 0:00 ` Keith Thompson
1999-09-14 0:00 ` Robert Dewar
1999-09-13 0:00 ` Ted Dennison
1999-09-13 0:00 ` Robert A Duff
1999-09-13 0:00 ` Robert Dewar
1999-09-10 0:00 ` Matthew Heaney
1999-09-10 0:00 ` Robert Dewar
1999-09-10 0:00 ` Ted Dennison
1999-09-10 0:00 ` Robert Dewar
1999-09-13 0:00 ` Ted Dennison
1999-09-13 0:00 ` Alex
-- strict thread matches above, loose matches on Subject: below --
2004-01-01 20:44 Luke A. Guest
2004-01-01 21:45 ` Stephen Leake
2004-01-01 22:01 ` Luke A. Guest
2004-01-02 1:17 ` tmoran
2004-01-02 1:29 ` Stephen Leake
2004-01-02 3:10 ` Luke A. Guest
2004-01-02 2:46 ` Robert A Duff
2004-01-02 3:12 ` Luke A. Guest
2004-01-02 13:58 ` Marin David Condic
2004-01-02 21:39 ` Pat Rogers
2004-01-03 13:42 ` Marin David Condic
2004-01-03 1:53 ` Robert A Duff
2004-01-02 20:52 ` Randy Brukardt
2004-01-02 21:05 ` Luke A. Guest
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox