comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org>
Subject: Re: What is the best way to convert Integer to Short_Short_Integer?
Date: Fri, 11 Jun 2010 00:07:16 -0700
Date: 2010-06-11T00:07:16-07:00	[thread overview]
Message-ID: <husneh$r0d$1@tornado.tornevall.net> (raw)
In-Reply-To: <e4ee8519-9b92-4b50-91eb-169cdb4b00c8@q39g2000prh.googlegroups.com>

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



  reply	other threads:[~2010-06-11  7:07 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-11  1:17 What is the best way to convert Integer to Short_Short_Integer? Adrian Hoe
2010-06-11  2:21 ` Adrian Hoe
2010-06-11  3:14 ` Jeffrey R. Carter
2010-06-11  4:26   ` Adrian Hoe
2010-06-11  7:07     ` Jeffrey R. Carter [this message]
2010-06-11  8:59       ` J-P. Rosen
2010-06-11 12:28       ` Maciej Sobczak
2010-06-11 19:05         ` Randy Brukardt
2010-06-13  4:26         ` BrianG
2010-06-13 18:07           ` Maciej Sobczak
2010-06-14  7:28             ` Georg Bauhaus
2010-06-14 16:45             ` Keith Thompson
2010-06-15  4:54               ` Martin Krischik
2010-06-22 21:48                 ` Keith Thompson
2010-06-15  2:24             ` BrianG
2010-06-15 21:21               ` Maciej Sobczak
2010-06-15 23:39                 ` Georg Bauhaus
2010-06-16  1:27                 ` BrianG
2010-06-11 12:31       ` Brian Drummond
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox