From: "Pat Rogers" <progers@classwide.com>
Subject: Re: [HELP] Why is 'Adjust' not called here ???
Date: Tue, 05 Feb 2002 16:03:55 GMT
Date: 2002-02-05T16:03:55+00:00 [thread overview]
Message-ID: <LnT78.1276$g87.413451421@newssvr12.news.prodigy.com> (raw)
In-Reply-To: 3C5FB880.6FD36A12@hotmail.com
"Didier Pieroux" <dpieroux@pi.be> wrote in message
news:3C5FB880.6FD36A12@hotmail.com...
> Hello,
>
> To make it short: why is 'Adjust' not called during initialization by a
> aggregate ?
>
> 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;
It is because the first case is initialization via an aggregate, but the second
case (immediately above) is not via an aggregate.
> 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 ?
See below.
> - Give me the key reference(s) in the RM from which this behavior can be
> deduced ?
RM 7.6 {17.1/1} {For an aggregate of a controlled type whose value is assigned,
other
than by an assignment_statement or a return_statement, the implementation
shall not create a separate anonymous object for the aggregate. The aggregate
value shall be constructed directly in the target of the assignment operation
and Adjust is not called on the target object.}
17.h.1/1 Reason: This is necessary to prevent elaboration problems with deferred
constants of controlled types. Consider:
package P is
type Dyn_String is private;
Null_String : constant Dyn_String;
...
private
type Dyn_String is new Ada.Finalization.Controlled with ...
procedure Finalize(X : in out Dyn_String);
procedure Adjust(X : in out Dyn_String);
Null_String : constant Dyn_String :=
(Ada.Finalization.Controlled with ...);
...
end P;
17.h.3/1 When Null_String is elaborated, the bodies of Finalize and Adjust
clearly have not been elaborated. Without this rule, this declaration would
necessarily raise Program_Error (unless the permissions given below are used by
the compiler).
---
Patrick Rogers Consulting and Training in:
http://www.classwide.com Real-Time/OO Languages
progers@classwide.com Hard Deadline Schedulability Analysis
(281)648-3165 Software Fault Tolerance
next prev parent reply other threads:[~2002-02-05 16:03 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 [this message]
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 ` [HELP] " Tucker Taft
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox