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, MSGID_RANDY 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: Robert Dewar Subject: Re: Enumeration representation Date: 1999/09/10 Message-ID: <7rbvlr$257$1@nnrp1.deja.com>#1/1 X-Deja-AN: 523524789 References: <37D8E3BC.175DB72C@newtech.it> <7rava6$kht@hobbes.crc.com> X-Http-Proxy: 1.0 x21.deja.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja.com - Share what you know. Learn what you don't. X-Article-Creation-Date: Fri Sep 10 22:11:14 1999 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1999-09-10T00:00:00+00:00 List-Id: In article <7rava6$kht@hobbes.crc.com>, "David C. Hoos, Sr." wrote: > > Alex wrote in message > news:37D8E3BC.175DB72C@newtech.it... > > I've written the following example program for testing enumeration > > represetantion clause: > > > > with Ada.Text_IO; use Ada.Text_IO; > > > > > > procedure MainEnum is > > > > type Status is (a,b,c,d,e); > > pragma Discard_Names(Status); > > > > for Status use > > ( a => 0, > > b => 20, > > c => 400, > > d => 800, > > e => 1600); > > > > S : Status; > > begin > > S := b; > > Put(" => " & S'img); > > end MainEnum; > > > > I've compiled it with Gnat (the latest version) > > the output of program is 1 but I was expecting another value : 20. > > Does Gnat support this clause? > I'm not sure to which clause you refer. > > > Did I use this clause badly? > > > > About the discard_names pragma the LRM says C.5 (7): > If the pragma applies to an enumeration type, then the semantics > of the Wide_Image and Wide_Value attributes are implementation > defined for that type; the semantics of Image and Value are still > defined in terms of Wide_Image and Wide_Value. In addition, the > semantics of Text_IO.Enumeration_IO are implementation defined. > If the pragma applies to a tagged type, then the semantics of the > Tags.Expanded_Name function are implementation defined for that > type. If the pragma applies to an exception, then the semantics > of the Exceptions.Exception_Name function are implementation > defined for that exception. > > The GNAT Reference Manual is not entirely correct in what it > states about this pragma, in that it says it is ignored. What > really happens, is that the Image attribute returns instead > of the image of the name, the image of the 'pos attribute.' Well my copy of the reference manual does not say that, as I quoted in my previous message. It is possible that versions of the reference manual for old versions of GNAT are out of date .. > > To do what you want to do, you need an instance of > Ada.Unchecked_Conversion, as demonstrated in this modification > of your program: > > with Ada.Text_Io; > use Ada.Text_Io; > with Ada.Unchecked_Conversion; > procedure MainEnum is > > type Status is (a,b,c,d,e); > pragma Discard_Names(Status); > > for Status use > ( a => 0, > b => 20, > c => 400, > d => 800, > e => 1600); > type Status_Rep is mod 2 ** Status'Size; > > function Rep is new Ada.Unchecked_Conversion > (Source => Status, > Target => Status_rep); > > -- S : Status; > begin > for S in Status'Range loop > Put("pos => " & S'img); > Put_Line ("; rep =>" & Rep(S)'Img); > end loop; > end MainEnum; > > Abitavo a Milano dal 6/1963 al 11/1965, e il mio > Italiano non e' quanto fluente come era allora ;) > Or, as noted in the previous post, 'Enum_Rep Sent via Deja.com http://www.deja.com/ Share what you know. Learn what you don't.