comp.lang.ada
 help / color / mirror / Atom feed
From: Adrian Hoe <abyhoe@gmail.com>
Subject: Re: What is the best way to convert Integer to Short_Short_Integer?
Date: Thu, 10 Jun 2010 19:21:48 -0700 (PDT)
Date: 2010-06-10T19:21:48-07:00	[thread overview]
Message-ID: <90d21c4c-6c2d-4cc7-8183-acc3316386b7@z15g2000prh.googlegroups.com> (raw)
In-Reply-To: d865bdeb-e4eb-4855-b4aa-f0f31f4777fa@s1g2000prf.googlegroups.com

On Jun 11, 9:17 am, Adrian Hoe <aby...@gmail.com> 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
>    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

Sorry, I forgot to convert Short_Short_Integer'First and
Short_Short_Integer'Last to Integer.
--
Adrian Hoe



  reply	other threads:[~2010-06-11  2:21 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 [this message]
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