comp.lang.ada
 help / color / mirror / Atom feed
* Limited_Controlled types as 'out' arguments
@ 2003-07-30 11:31 Lutz Donnerhacke
  2003-07-30 12:22 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 25+ messages in thread
From: Lutz Donnerhacke @ 2003-07-30 11:31 UTC (permalink / raw)


I'm using an Limited_Controlled type as an 'out' parameter of a procedure.
While programming this procedure in question, I wonder how to Finalize the
object given as argument to the 'out' parameter.

------------------------------------------------------------------------
with Ada.Finalization;

package t1 is
   type Test is new Ada.Finalization.Limited_Controlled with record
      a : Character;
   end record;
   procedure Initialize(o : in out Test);
   procedure Finalize(o : in out Test);
   procedure Copy(to : out Test; from : Test);
end t1;
------------------------------------------------------------------------
with t1;
use t1;

procedure t is
   a, b, c : Test;
begin
   Copy(a, b);
   Copy(a, c);
end t;
------------------------------------------------------------------------
with Ada.Text_IO;
use Ada.Text_IO;

package body t1 is
   global : Character := '0';
   
   procedure Initialize(o : in out Test) is
   begin
      o.a := global;
      Put_Line("Initializing " & o.a);
      global := Character'Succ(global);
   end Initialize;
   
   procedure Finalize(o : in out Test) is
   begin
      Put_Line("Finalizing " & o.a);
   end Finalize;
   
   procedure Copy(to : out Test; from : Test) is
   begin
      to.a := global;
      Put_Line("Copying " & from.a & " to " & to.a);
      global := Character'Succ(global);
   end Copy;
end t1;
------------------------------------------------------------------------

This results in:
   Initializing 0
   Initializing 1
   Initializing 2
   Copying 1 to 3
   Copying 2 to 4
   Finalizing 2
   Finalizing 1
   Finalizing 4

Clearly, the variable 0 and 3 are never finalized. How implement I this
correctly (without refering to the rosen trick).



^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2003-07-31 17:51 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-30 11:31 Limited_Controlled types as 'out' arguments Lutz Donnerhacke
2003-07-30 12:22 ` Dmitry A. Kazakov
2003-07-30 12:32   ` Lutz Donnerhacke
2003-07-30 14:24     ` Dmitry A. Kazakov
2003-07-30 14:25       ` Lutz Donnerhacke
2003-07-30 14:48         ` Dmitry A. Kazakov
2003-07-30 15:15           ` Lutz Donnerhacke
2003-07-31 10:26             ` Dmitry A. Kazakov
2003-07-31 10:54               ` Lutz Donnerhacke
2003-07-31 11:50                 ` Dmitry A. Kazakov
2003-07-31 12:19                   ` Lutz Donnerhacke
2003-07-31 13:15                     ` Dmitry A. Kazakov
2003-07-31 17:51                 ` Randy Brukardt
2003-07-30 15:01         ` Vinzent Hoefler
2003-07-30 15:16           ` Lutz Donnerhacke
2003-07-30 15:52         ` Lutz Donnerhacke
2003-07-30 19:30           ` Randy Brukardt
2003-07-31  7:43             ` Lutz Donnerhacke
2003-07-30 12:31 ` Matthew Heaney
2003-07-30 12:57   ` Lutz Donnerhacke
2003-07-30 13:47     ` Martin Dowie
2003-07-30 17:06     ` Matthew Heaney
2003-07-30 12:37 ` Martin Dowie
2003-07-30 12:59   ` Lutz Donnerhacke
2003-07-30 13:41     ` Martin Dowie

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