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: "Matthew Heaney" Subject: Re: Enumeration representation Date: 1999/09/10 Message-ID: <37d9061a@news1.prserv.net>#1/1 X-Deja-AN: 523373892 Content-transfer-encoding: 7bit References: <37D8E3BC.175DB72C@newtech.it> Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 10 Sep 1999 13:22:34 GMT, 129.37.62.210 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-09-10T00:00:00+00:00 List-Id: In article <37D8E3BC.175DB72C@newtech.it> , Alex wrote: > 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); Why did you use Discard_Names? > for Status use > ( a => 0, > b => 20, > c => 400, > d => 800, > e => 1600); > > S : Status; > begin > S := b; > Put(" => " & S'img); The image of literal B is of course "B". But I don't know what 'Img will return if you also use pragma Discard_Names. > end MainEnum; > > I've compiled it with Gnat (the latest version) > the output of program is 1 but I was expecting another value : 20. GNAT seems to be displaying the value of T'Pos. You want to underlying representation. If so, you'll have use Unchecked_Conversion to convert the literal to an integer, and then display that. An alternative is to use the GNAT-specific attribute 'Enum_Rep (I think that's what it's called). But if you really want to display 20, then why did you use an enumeration type at all? Why not do this: type Status_Type is range 0 .. 1600; A : constant Status_Type := 0; B : constant Status_Type := 20; -- 20 or 200? C : constant Status_Type := 400; D : constant Status_Type := 800; E : constant Status_Type := 1600; This is more or less equivalent to what you had using an enumeration type. The difference is that Status_Type'Image (B) returns " 20", which is what you wanted. > Does Gnat support this clause? The pragma Discard_Names? Look in Annex M of the GNAT User's Guide or Reference Manual. Why do you need that pragma anyway? Do you have some storage restrictions? > Did I use this clause badly? I think so. Give us some more specific information about what you're trying to do. > Thank you very much, You're very welcome. Matt