comp.lang.ada
 help / color / mirror / Atom feed
* What is the best way to convert Integer to Short_Short_Integer?
@ 2010-06-11  1:17 Adrian Hoe
  2010-06-11  2:21 ` Adrian Hoe
  2010-06-11  3:14 ` Jeffrey R. Carter
  0 siblings, 2 replies; 19+ messages in thread
From: Adrian Hoe @ 2010-06-11  1:17 UTC (permalink / raw)


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
   function Convert_To_Short_Short_Integer is new
      Ada.Unchecked_Conversion ( Integer, Short_Short_Integer ) ;
begin
   If I >= Short_Short_Integer'First and I <= Short_Short_Integer'Last
then
      return Convert_To_Short_Short_Integer ( I );
   else
      raise Range_Error;
   end 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



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2010-06-22 21:48 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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