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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e1bb40a3d604c4b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!z15g2000prh.googlegroups.com!not-for-mail From: Adrian Hoe Newsgroups: comp.lang.ada Subject: Re: What is the best way to convert Integer to Short_Short_Integer? Date: Thu, 10 Jun 2010 19:21:48 -0700 (PDT) Organization: http://groups.google.com Message-ID: <90d21c4c-6c2d-4cc7-8183-acc3316386b7@z15g2000prh.googlegroups.com> References: NNTP-Posting-Host: 60.53.27.161 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1276222908 1044 127.0.0.1 (11 Jun 2010 02:21:48 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 11 Jun 2010 02:21:48 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z15g2000prh.googlegroups.com; posting-host=60.53.27.161; posting-account=coq9PAkAAAB2Xx46RZLFJw5dY9DVXW4- User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:12595 Date: 2010-06-10T19:21:48-07:00 List-Id: On Jun 11, 9:17=A0am, Adrian Hoe wrote: > Hi, > > Perhaps I have overlook the repository. What is the best (safest) way > to convert an Integer to Short_Short_Integer? > > 1. Using Ada.Unchecked_Conversion raises warning types of unchecked > conversion have different size. > > 2. Using a custom function such as: > > function To_Short_Short_Integer ( I : Integer ) return > SHort_Short_Integer > is > =A0 =A0function Convert_To_Short_Short_Integer is new > =A0 =A0 =A0 Ada.Unchecked_Conversion ( Integer, Short_Short_Integer ) ; > begin > =A0 =A0If I >=3D Short_Short_Integer'First and I <=3D Short_Short_Integer= 'Last > then > =A0 =A0 =A0 return Convert_To_Short_Short_Integer ( I ); > =A0 =A0else > =A0 =A0 =A0 raise Range_Error; > =A0 =A0end if; > end To_Short_Short_Integer; > > Again, the Unchecked_Conversion will raise the same warning in (1). > > Is (2) the best (safest) way to do the conversion? Is there any better > method? > > Thanks. > -- > Adrian Hoe Sorry, I forgot to convert Short_Short_Integer'First and Short_Short_Integer'Last to Integer. -- Adrian Hoe