* Re: [Thanks] Why is 'Adjust' not called here ???
@ 2002-02-06 11:23 Christoph Grein
0 siblings, 0 replies; 2+ messages in thread
From: Christoph Grein @ 2002-02-06 11:23 UTC (permalink / raw)
> By the way, by reading your answers I discovered that the reason for me
> not finding the correct reference was that I was using the "On-line
> version of the Ada 95 Rationale at AdaPower.com" which is clearly
> missing the "Implementation Requirements" you refer to. So I guess that
> it is not up to date and misses the last corrections. Hough !
>
> Now, I know it is better to consult
> "www.ada-auth.org/arm-html/RM-TOC.html" instead ;-)
Please note that the "Ada 95 Rationale" is just that, the "rationale" about the
Reference Manual, it is _not_ the "Reference Manual" itself.
The Rationale _is_ up to date.
I do not know whether the URL above is the correct one for "Reference Manual
with Technical Corrigendum 1". Watch out. The latter is definitely somewhere at
that site.
HTH
^ permalink raw reply [flat|nested] 2+ messages in thread
* [HELP] Why is 'Adjust' not called here ???
@ 2002-02-05 10:48 Didier Pieroux
2002-02-05 16:03 ` Pat Rogers
0 siblings, 1 reply; 2+ messages in thread
From: Didier Pieroux @ 2002-02-05 10:48 UTC (permalink / raw)
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;
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
== a.ads =============================================================
with Ada.Finalization;
package A is
type Instance is new Ada.Finalization.Controlled with
record
N: Integer;
end record;
procedure Initialize(Self: in out Instance);
procedure Adjust (Self: in out Instance);
procedure Finalize (Self: in out Instance);
end A;
== a.adb =============================================================
with Ada.Text_Io;
use Ada.Text_Io;
package body A is
procedure Initialize(Self: in out Instance) is
begin
Put_Line("Init");
end;
procedure Adjust(Self: in out Instance) is
begin
Put_Line("Adjust");
end;
procedure Finalize(Self: in out Instance) is
begin
Put_Line("Finalize");
end;
end A;
== my_test.adb =======================================================
with Ada.Finalization;
with A;
procedure My_Test is
Item1 : A.Instance := (Ada.Finalization.Controlled with 10);
Item2 : A.Instance := Item1;
begin
null;
end My_Test;
== Result: ===========================================================
~/Ada/test > gnatmake my_test.adb
gnatgcc -c my_test.adb
gnatgcc -c a.adb
gnatbind -x my_test.ali
gnatlink my_test.ali
~/Ada/test > my_test
Adjust <-- this corresponds to the Item2 elaboration.
Finalize
Finalize
~/Ada/test >
--
_________________________________________________________________
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
_________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [HELP] Why is 'Adjust' not called here ???
2002-02-05 10:48 [HELP] " Didier Pieroux
@ 2002-02-05 16:03 ` Pat Rogers
2002-02-05 16:16 ` Stephen Leake
0 siblings, 1 reply; 2+ messages in thread
From: Pat Rogers @ 2002-02-05 16:03 UTC (permalink / raw)
"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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [HELP] Why is 'Adjust' not called here ???
2002-02-05 16:03 ` Pat Rogers
@ 2002-02-05 16:16 ` Stephen Leake
2002-02-05 17:07 ` Pat Rogers
0 siblings, 1 reply; 2+ messages in thread
From: Stephen Leake @ 2002-02-05 16:16 UTC (permalink / raw)
> "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 ?
Because the RM says so :). Pat Rogers gave the RM references.
I believe the rationale is that you can only do initialization by
aggregate in the body of the package defining the type, so you are
assumed to know what you are doing, and should do the equivalent of
the Adjust processing while building the aggregate.
Hmm, what I said about "body of the package" is strictly true only for
limited controlled types. Still, if you have visibility so you can
build an aggregate, you are presumed to know what you are doing.
--
-- Stephe
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [HELP] Why is 'Adjust' not called here ???
2002-02-05 16:16 ` Stephen Leake
@ 2002-02-05 17:07 ` Pat Rogers
2002-02-06 10:01 ` [Thanks] " Didier Pieroux
0 siblings, 1 reply; 2+ messages in thread
From: Pat Rogers @ 2002-02-05 17:07 UTC (permalink / raw)
"Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov> wrote in message
news:uofj3ucng.fsf@gsfc.nasa.gov...
> > "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 ?
>
> Because the RM says so :). Pat Rogers gave the RM references.
>
> I believe the rationale is that you can only do initialization by
> aggregate in the body of the package defining the type, so you are
> assumed to know what you are doing, and should do the equivalent of
> the Adjust processing while building the aggregate.
>
> Hmm, what I said about "body of the package" is strictly true only for
> limited controlled types. Still, if you have visibility so you can
> build an aggregate, you are presumed to know what you are doing.
The AARM gives the reason, though it is quite "pedestrian":
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).
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Thanks] Why is 'Adjust' not called here ???
2002-02-05 17:07 ` Pat Rogers
@ 2002-02-06 10:01 ` Didier Pieroux
0 siblings, 0 replies; 2+ messages in thread
From: Didier Pieroux @ 2002-02-06 10:01 UTC (permalink / raw)
Pat Rogers wrote:
> > Because the RM says so :). Pat Rogers gave the RM references.
Dear Pat and Stephen,
Thanks to you !
By the way, by reading your answers I discovered that the reason for me
not finding the correct reference was that I was using the "On-line
version of the Ada 95 Rationale at AdaPower.com" which is clearly
missing the "Implementation Requirements" you refer to. So I guess that
it is not up to date and misses the last corrections. Hough !
Now, I know it is better to consult
"www.ada-auth.org/arm-html/RM-TOC.html" instead ;-)
Best regards,
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
http://www.ulb.ac.be/sciences/ont/en.html
_________________________________________________________________
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-02-06 11:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-06 11:23 [Thanks] Why is 'Adjust' not called here ??? Christoph Grein
-- strict thread matches above, loose matches on Subject: below --
2002-02-05 10:48 [HELP] " 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox