From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,c9f437cff8842e X-Google-Attributes: gid103376,public From: Keith Thompson Subject: Re: Enumeration representation Date: 1999/09/10 Message-ID: #1/1 X-Deja-AN: 523572025 Sender: kst@king.cts.com References: <37D8E3BC.175DB72C@newtech.it> X-Trace: nusku.cts.com 937004262 72689 198.68.168.21 (10 Sep 1999 22:57:42 GMT) Organization: CTS Network Services Newsgroups: comp.lang.ada X-Complaints-To: newsmaster@cts.com Date: 1999-09-10T00:00:00+00:00 List-Id: Alex 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 San Diego Supercomputer Center <*> "Oh my gosh! You are SO ahead of your time!" -- anon.