comp.lang.ada
 help / color / mirror / Atom feed
From: Tucker Taft <stt@avercom.net>
Subject: Re: [HELP] Why is 'Adjust' not called here ???
Date: Thu, 14 Feb 2002 15:05:05 -0500
Date: 2002-02-14T20:05:05+00:00	[thread overview]
Message-ID: <3C6C1871.AF871003@avercom.net> (raw)
In-Reply-To: 3C5FB880.6FD36A12@hotmail.com

Didier Pieroux wrote:
> 
> Hello,
> 
> To make it short: why is 'Adjust' not called during initialization by a
> aggregate ?

We debated this during the Ada 95 design process.  We decided that
Adjust is called after *copying* an existing value, Initialize is
called to create a (new) value by default initialization, and an aggregate
may be used to create a new value exactly as you want it to end up.
Calling Adjust after evaluating the aggregate could be confusing.
Of course, we could have done it otherwise, and required that
when you write an aggregate, you keep in mind that Adjust is
going to be applied to it.

The second issue is whether an aggregate used to initialize an
object should be built in a temporary and then copied into
the object, or built "in place."  There are many advantages
to requiring that the aggregate be built "in place."  As mentioned
elsewhere, it allows you to initialize constants *before* the
Adjust and Finalize procedures have been elaborated.  Secondly,
it avoids the need to allocate space for the temp, copy the
temp into the declared object, adjust the declared object,
finalize the temp, and deallocate the temp.  Of course allocation/deallocation
might be cheap due to being on the stack, but the copy, adjust, and finalize
could be expensive.  The original Ada 95 RM didn't require that you
build the aggregate in place, but a subsequent "Ada Interpretation" (AI-83)
has made this an implementation requirement, to allow portable
programs to declare and initialize constants with aggregates.

If you want to read AI-83, go to:

   http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00083.TXT?rev=1.16


> 
> I give an example below illustrating my question.  'A.Instance' is a
> controlled type with Initialize, Adjust and Finalize redefined to print
> their name.
> 
> I thought that the elaboration of
> 
>    Item1 : A.Instance := (Ada.Finalization.Controlled with 10);
> 
> would call the 'A.Adjust' procedure... It is not the case. However,
> 'A.Adjust' is called as expected after the elaboration of
> 
>    Item2 : A.Instance := Item1;
> 
> I check that behavior with both the Gnat and Aonix compiler.  So, I am
> clearly missing something here, and I can't find the answer in my books
> (Barnes, Cohen, Ben-Ari and the RM)
> 
> Also, could someone
> - Explain me the rational for not calling 'Adjust' in the first case ?
> - Give me the key reference(s) in the RM from which this behavior can be
> deduced ?
> 
> Thank in advance for the light !
> Didier
>...
>      _________________________________________________________________
> 
>      Didier Pieroux
>      Theoretical Nonlinear Optics, CP 231
>      Physics Department, Universite Libre de Bruxelles
>      Bvd du Triomphe, B-1050 Brussels, Belgium
> 
>      Phone: ++ 32 2 650 5903, Fax: ++ 32 2 650 5824
>      dpieroux@hotmail.com
>      _________________________________________________________________

-- 
-Tucker Taft   stt@avercom.net   http://www.avercom.net
Chief Technology Officer, AverCom Corporation (A Titan Company) 
Bedford, MA  USA (AverCom was formerly the Commercial Division of AverStar:
http://www.averstar.com/~stt)



      parent reply	other threads:[~2002-02-14 20:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-05 10:48 [HELP] Why is 'Adjust' not called here ??? Didier Pieroux
2002-02-05 16:03 ` Pat Rogers
2002-02-05 16:16   ` Stephen Leake
2002-02-05 17:07     ` Pat Rogers
2002-02-06 10:01       ` [Thanks] " Didier Pieroux
2002-02-14 20:05 ` Tucker Taft [this message]
replies disabled

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