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=-0.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9bb56e94a4c5bb5e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!cyclone1.gnilink.net!spamkiller2.gnilink.net!gnilink.net!trndny08.POSTED!0f19ed38!not-for-mail From: "Frank J. Lhota" Newsgroups: comp.lang.ada References: Subject: Re: How unchecked conversion works? X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Response Message-ID: Date: Thu, 13 Jan 2005 21:22:22 GMT NNTP-Posting-Host: 68.163.175.141 X-Complaints-To: abuse@verizon.net X-Trace: trndny08 1105651342 68.163.175.141 (Thu, 13 Jan 2005 16:22:22 EST) NNTP-Posting-Date: Thu, 13 Jan 2005 16:22:22 EST Xref: g2news1.google.com comp.lang.ada:7738 Date: 2005-01-13T21:22:22+00:00 List-Id: You would not use Unchecked_Conversion to convert a float to an integer. Basically, Unchecked_Conversion takes an object S of type Source and pretend it is an object of type Target, simply by assuming that an object of type Target resides at the same address as S. In other words, if we define function Convert is new Ada.Unchecked_Conversion( Source, Target ); S : Source; then the Ada call Convert( S ) does basically the same thing as the following C code: *( (Target *) &S ) Needless to say, the result of unchecked conversion depends heavily on the internal representation of the Source and Target types. This type of conversion is inherently risky in either C or Ada, which is why Ada makes it difficult to do unchecked conversions. You almost certainly do not want to do an unchecked conversion to change a float into an integer. The integer resulting from such a conversion would have little to do with the original floating point number. Most likely you want to do a straighforward type conversion. For example: type My_Float is digits 6; type My_Integer is range 1 .. 10; S : My_Float; Then we can convert S into a My_Integer value by writing My_Integer( S ) That's it!