comp.lang.ada
 help / color / mirror / Atom feed
* [HELP] Why is 'Adjust' not called here ???
@ 2002-02-05 10:48 Didier Pieroux
  2002-02-05 16:03 ` Pat Rogers
  2002-02-14 20:05 ` [HELP] " Tucker Taft
  0 siblings, 2 replies; 7+ 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] 7+ messages in thread
* Re: [Thanks] Why is 'Adjust' not called here ???
@ 2002-02-06 11:23 Christoph Grein
  0 siblings, 0 replies; 7+ 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] 7+ messages in thread

end of thread, other threads:[~2002-02-14 20:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [HELP] " Tucker Taft
  -- strict thread matches above, loose matches on Subject: below --
2002-02-06 11:23 [Thanks] " Christoph Grein

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