comp.lang.ada
 help / color / mirror / Atom feed
From: Adrian Hoe <abyhoe@gmail.com>
Subject: What is the best way to convert Integer to Short_Short_Integer?
Date: Thu, 10 Jun 2010 18:17:12 -0700 (PDT)
Date: 2010-06-10T18:17:12-07:00	[thread overview]
Message-ID: <d865bdeb-e4eb-4855-b4aa-f0f31f4777fa@s1g2000prf.googlegroups.com> (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



             reply	other threads:[~2010-06-11  1:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-11  1:17 Adrian Hoe [this message]
2010-06-11  2:21 ` What is the best way to convert Integer to Short_Short_Integer? 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
replies disabled

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