comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: Questions about Unchecked_Conversion
Date: 1999/12/15
Date: 1999-12-15T00:00:00+00:00	[thread overview]
Message-ID: <38581422_2@news1.prserv.net> (raw)
In-Reply-To: 19991215201559.23735.qmail@web218.mail.yahoo.com

In article <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?

Ada is a strongly-typed language, which basically means you can't mix
apples and oranges.

Unchecked_Conversion is the mechanism the language provides for
bypassing the type system, in effect allowing you to convert an apple
into an orange.


> 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);

What does function ABC do?  Without knowing that, it's impossible to
make a comparison.

In any case, the profile doesn't match anyway.  UC is a generic function
that takes a single argument (and returns a single value):

  function To_B_Type is
    new Unchecked_Conversion (Source => A_Type, Target => B_Type);

  B : constant B_Type := To_B_Type (A);


> 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?

I'm not sure what you're asking here.  If you mean can you implement a
function using UC, the answer is yes:

package P is
  function To_B_Type (A : A_Type) return B_Type;
end;

with Unchecked_Conversion;
package body P is

  function UC_To_B_Type is
    new Unchecked_Conversion (A_Type, B_Type);

  function To_B_Type (A : A_Type) return B_Type renames
    UC_To_B_Type;

end;


> 3. What happens if we place the statement With Unchecked_Conversion;
>    somewhere in the top of our program?

Nothing, unless you instantiate the generic, and then call the
instantiation during an execution of your program.


> Does this mean that from then on, and for the whole pgm, no conversion
> exception is raised anywhere?

No.  If you're trying to suppress exceptions, there are other mechanisms
for doing that.


--
Yeah, well, no one was present when the dinosaurs lived, so I guess
their presence in the fossil record is "only a theory." No one was
present when the Grand Canyon was formed either, or the creation of the
solar system, or, or, or. Of course evolution is "only a theory." What
else would it be as a scientific concept?

Skeptic magazine publisher Micheal Shermer, commenting on the recent
decision by the Oklahoma board of education to include a disclaimer on
school science textbooks warning that evolution is "only a theory."

Skeptic web page: http://www.skeptic.com/




  reply	other threads:[~1999-12-15  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 ` Matthew Heaney [this message]
1999-12-15  0:00 ` reason67
1999-12-16  0:00 ` Charles H. Sampson
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