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 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: claveman@inetworld.net (Charles H. Sampson) Subject: Re: Questions about Unchecked_Conversion Date: 1999/12/16 Message-ID: <1e2w3op.j44mmjevrxz4N%claveman@inetworld.net>#1/1 X-Deja-AN: 561504085 References: <19991215201559.23735.qmail@web218.mail.yahoo.com> X-Trace: newsfeed.slurp.net 945349704 209.132.125.146 (Thu, 16 Dec 1999 07:08:24 CDT) User-Agent: MacSOUP/2.4.2 NNTP-Posting-Date: Thu, 16 Dec 1999 07:08:24 CDT Newsgroups: comp.lang.ada Date: 1999-12-16T00:00:00+00:00 List-Id: MaryAnn Atkinson 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? The rest of your post makes it look like you're a bit hazy on ex- actly what Unchecked_Conversion (hereafter referred to as UC) is, not surprising because the Ada terminology is a bit confusing. It's called a generic function, but it's not really a function. Instead, it's a blueprint or a template used by the compiler to create real functions. The functions created, called instantiations, will take the bit pattern that represents a value of one type and treat it as a value of another type. Notice that this means that there is no attempt to con- vert the original value to a value of the new type. Indeed, as the name implies, no checking at all goes on that the bit pattern is proper as a value of the new type. Notice also that this is highly hardware dependent. Use with care. However, don't avoid it because of this dependency when you really need it. (Programming standards that proscribe UC are unrealistic. Fortu- nately, there seem to be fewer of these now.) I don't understand your question "What if I dont have it there?". > 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); If you were declare KLM without using UC, its specification would be something like FUNCTION KLM (Original_Bits : Type_of_A) RETURN Type_of_B; Thus the two are not at all comparable. Maybe this question needs clar- ification too. > 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? Without clarification, KLM could not be defined the same as ABC. In any case, you can't put a WITH Unchecked_Conversion in the body of KLM. A with_clause can only go in the context clause of a compila- tion, before the stuff you want to compile. > 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? At the top of the program is the right place for it, but it can't just go somewhere at the top. It must come before the thing you're com- piling, in the so-called context clause of the compilation: with Unchecked_Conversion; package body A_package is ... (Intervening comments and white space are o. k.) Such a with statement does nothing about suppressing "conversion exceptions" at all. It simply means that for this compilation unit you, the programmer, are free to use UC. Its effect is only on that compila- tion, not the program as a whole. (Technically there's no such thing as a "conversion exception", but I think you mean, "an exception raised during a type conversion.") Charlie -- To get my correct email address, replace the "claveman" by "csampson" in my fake (anti-spam) address.