comp.lang.ada
 help / color / mirror / Atom feed
From: claveman@inetworld.net (Charles H. Sampson)
Subject: Re: Questions about Unchecked_Conversion
Date: 1999/12/16
Date: 1999-12-16T00:00:00+00:00	[thread overview]
Message-ID: <1e2w3op.j44mmjevrxz4N%claveman@inetworld.net> (raw)
In-Reply-To: 19991215201559.23735.qmail@web218.mail.yahoo.com

MaryAnn Atkinson <maryann_30@yahoo.com> 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.




  parent reply	other threads:[~1999-12-16  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-15  0:00 Questions about Unchecked_Conversion MaryAnn Atkinson
1999-12-15  0:00 ` reason67
1999-12-15  0:00 ` Matthew Heaney
1999-12-16  0:00 ` Charles H. Sampson [this message]
1999-12-16  0:00   ` Matthew Heaney
1999-12-17  0:00     ` reason67
1999-12-18  0:00     ` Charles H. Sampson
replies disabled

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