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=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7532bb41d4ac458d X-Google-Attributes: gid103376,public From: reason67@my-deja.com Subject: Re: Questions about Unchecked_Conversion Date: 1999/12/15 Message-ID: <8396b3$p6p$1@nnrp1.deja.com>#1/1 X-Deja-AN: 561134105 References: <19991215201559.23735.qmail@web218.mail.yahoo.com> X-Http-Proxy: NetCache@www-blv-proxy6.boeing.com: Version NetApp Release 3.4D6: Mon Aug 23 16:40:19 PDT 1999-Solaris, 1.0 x32.deja.com:80 (Squid/1.1.22) for client 12.13.226.16 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Wed Dec 15 22:56:38 1999 GMT X-MyDeja-Info: XMYDJUIDreason67 Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.05 [en]C-Boeing Kit (Win95; I) Date: 1999-12-15T00:00:00+00:00 List-Id: In article <19991215201559.23735.qmail@web218.mail.yahoo.com>, comp.lang.ada@ada.eu.org wrote: > 1. Could someone please explain a few things about Unchecked Conversion > and what it really does for me? What if I dont have it there? NOTE: I am assuming Ada83 as you used Ada83 names.. If it is 95, my explainations still apply but my examples could be written better. Unchecked conversion is just as the name says. It converts data from one type to another without doing any error checking. So if you had: type Traffic_Light_Type is (Red, Yellow, Green); for Traffic_Light_Type use (Red => 15, Yellow => 45, Green => 60); for Traffic_Light_Type'Size use 16; type Word_Type is range 0 .. 65536; for Word_Type'Size use 16; function To_Traffic_Light_Type is new Unchecked_Conversion (Source => Word_Type, Target => Traffic_Light_Type); Word : Word_Type; Traffic_Light : Traffic_Light_Type; ... begin ... Traffic_Light := To_Traffic_Light_Type (Word); ... end; The conversion from Word to Traffic light is done unconditionally. If Word does not equal 15, 45, or 60, the conversion still happens with no error. Upon use of Traffic_Light, a Constraint_Error would be raised. If you do not use Unchecked_Conversion, you have to do the conversion manually. In my example, that is fairly easy. But if converting between a 32 bit Float and an 4 byte array, that is far more complicated. Conversions such as that can not be done through type casting. > 2. What is the difference (as far as unchecked_conversion is concerned) > > between the following? > > a. FUNCTION ABC(A, B); > b. FUNCTION KLM IS NEW Unchecked_Conversion(A, B); ABC has a different spec then KLM. KLM only takes A as a parameter and returns B. > Could the KLM function be defined the same as the ABC function > above, > but in the body of the KLM function be placed a WITH > Unchecked_Conversion; > statement? Would this have the same effect? If the specs matched, yes. You could hide the use of Unchecked conversion in the body without changing the functionality at all. > 3. What happens if we place the statement With Unchecked_Conversion; > somewhere in the top of our program? Does this mean that from then > on, and for the whole pgm, no conversion exception is raised > anywhere? If you placed the with of unchecked_conversion before the package, it is visible thoughout the package. Withing in Unchecked_Conversions has absolutely no effect other than giving you package visibility to Unchecked_Conversion. Any type casting you do would still be subject to Ada type checking. The only thing that would be exempt would be the specific calls to instantiations of unchecked_conversion. --- Jeffrey S. Blatt Sent via Deja.com http://www.deja.com/ Before you buy.