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.9 required=5.0 tests=BAYES_00 autolearn=ham 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-7-bit Path: g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!feeder.erje.net!news.musoftware.de!wum.musoftware.de!news.tornevall.net!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: What is the best way to convert Integer to Short_Short_Integer? Date: Fri, 11 Jun 2010 00:07:16 -0700 Organization: TornevallNET - http://news.tornevall.net Message-ID: References: NNTP-Posting-Host: 82a13b478adfd013d267ddfdeff64a96 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: 1f93aa45296af86caf2a3f660cbed0dd X-Complaints-To: abuse@tornevall.net User-Agent: Thunderbird 2.0.0.24 (X11/20100411) X-Complaints-Language: Spoken language is english or swedish - NOT ITALIAN, FRENCH, GERMAN OR ANY OTHER LANGUAGE! In-Reply-To: X-Validate-Post: http://news.tornevall.net/validate.php?trace=1f93aa45296af86caf2a3f660cbed0dd X-SpeedUI: 1738 X-Complaints-Italiano: Non abbiamo padronanza della lingua italiana - se mandate una email scrivete solo in Inglese, grazie X-Posting-User: 0243687135df8c4b260dd4a9a93c79bd Xref: g2news1.google.com comp.lang.ada:11628 Date: 2010-06-11T00:07:16-07:00 List-Id: Adrian Hoe wrote: > > I have a number which is in the range of -128..127 and is read as > Integer (32-bit). The reason that I want to convert to > Short_Short_Integer is to save 24 bits of every such value stored in a > record type and to enforce its range on user input. The if..else > statement performs range checking during conversion. As long as the > range is checked, of course, we can use either method: type conversion > as Jeff suggested or use Unchecked_Conversion. Which byte of the 32-bit integer will Unchecked_Conversion return? > Which is the preferred method? Short_Short_Integer (I) or > Unchecked_Conversion? A type conversion is preferred. > And why Jeff said Short_Short_Integer not portable? Is the > implementation of Short_Short_Integer machine dependent? If > Short_Short_Integer is not portable, what is the best implementation > in your opinion? Convert to a smaller integer to save mere 24 bits or > keep it as 32-bit Integer and perform range checking? Implementations are not required to define Short_Short_Integer (or any other predefined integer type except Integer), so the program may fail on other compilers. Thus, the use of Short_Short_Integer is not portable. The best implementation may be influenced by many factors, but the best approach is to use types defined based on the problem, not predefined types based on the HW. -- Jeff Carter "In the frozen land of Nador they were forced to eat Robin's minstrels, and there was much rejoicing." Monty Python & the Holy Grail 70