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,7e29322ee367c19d X-Google-Attributes: gid103376,public From: Jeff Carter Subject: Re: Unchecked_Conversion on different sized types -- problem? Date: 2000/01/14 Message-ID: <85lso9$t80$1@nnrp1.deja.com>#1/1 X-Deja-AN: 572304097 References: X-Http-Proxy: 1.0 x42.deja.com:80 (Squid/1.1.22) for client 205.188.192.177 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Fri Jan 14 01:05:23 2000 GMT X-MyDeja-Info: XMYDJUIDjrcarter001 Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; AOL 5.0; Windows 95; DigExt; Freei Client 2.1) Date: 2000-01-14T00:00:00+00:00 List-Id: In article , "Mike Silva" wrote: > To do some prototyping I'm extending Michael Feldman's ANSI screen package a > bit, to allow colors, etc, and I ran into a question. I've enumerated > various attributes and set the enumerations to the corresponding ANSI codes, > and I'm using UC to convert the enumerated types to an Integer, to send via > Text_IO.Put(). I get a warning (GNAT 3.12p) that the types for the UC have > different sizes (not surprising), and I'm wondering if UC always does the > "right" thing here, i.e. zero-extending the smaller enum type when > converting to an Integer. > > Here are some (reduced) relevant code bits: > > type T is ( BLACK, WHITE ); > > for T use ( BLACK => 30, WHITE => 37 ); > > function T_to_int is new Unchecked_Conversion( T, Integer ); > > T_val : T := BLACK; > > Text_IO.Put( Item => T_to_int( T_val )... Text_Io works for Character and String, but not for Integer, so I'm curious how you get this to work. Perhaps what you want is a conversion from T to String, and you're using an intermediate Integer value to obtain this, in which case a set of String constants seems to be the easiest way to achieve this. Perhaps internally you would like to declare (assuming a with and use of Ada.Strings.Unbounded) type Conversion_List is array (T) of Unbounded_String: Convert : constant Conversion_List := (Black => To_Unbounded_String ("30"), ...); Text_Io.Put (Convert (Formal_Parameter_Of_Type_T) ); and get rid of the representation clause. > > So, is T_to_int going to give me 30, as opposed to, say, all 32 bits > starting at the address of T_val? Can somebody tell me where in the LRM it > talks about this? > > (It works "as expected" in this case, but I'm wondering what the rules are) ARM 13.9(11) says this is implementation defined. -- Jeff Carter "Now go away or I shall taunt you a second time." -- Monty Python and the Holy Grail Sent via Deja.com http://www.deja.com/ Before you buy.