comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: Limited_Controlled types as 'out' arguments
Date: Thu, 31 Jul 2003 15:15:43 +0200
Date: 2003-07-31T15:15:43+02:00	[thread overview]
Message-ID: <p55iivs8aq0mrl9u4fvud7f3bos5lte63d@4ax.com> (raw)
In-Reply-To: slrnbii29k.2j7.lutz@taranis.iks-jena.de

On Thu, 31 Jul 2003 12:19:17 +0000 (UTC), Lutz Donnerhacke
<lutz@iks-jena.de> wrote:

>* Dmitry A Kazakov wrote:
>> On Thu, 31 Jul 2003 10:54:44 +0000 (UTC), Lutz Donnerhacke
>>>   procedure Set(o1, o2 : out Test; i : Test) is
>>>   begin
>>>      Debug("Setting from", i.a);
>>>      Debug("Setting o1  ", o1.a);
>>>      Debug("Setting o2  ", o2.a);
>>>      Finalize(o1);
>>>      Finalize(o2);
>>>      
>>>      o1.a := new Character'(global);
>>>      Debug("Setting to1 ", o1.a);
>>>      global := Character'Succ(global);
>>>
>>>      o2.a := new Character'(i.a.all);
>>>      Debug("Setting to2 ", o2.a);
>>>   end Set;
>> 
>> Sort of, if you are calling Finalize from a normal subprogram! (:-))
>> As for error, you call Set (a, a, b); which finalizes a twice! It is a
>> language design fault that a destructor can be called explicitly. Your
>> example shows why.
>
>Changing the "Finalize" calls to "Free" causes the same effect.
>So the main point is: How to manage resources correctly?

What do you mean? Aliasing problem or assignment of limited types?
Anyway what should not be confused is that assignment, copy
constructor, copy procedure, all are very different things.

>   procedure Set(o1, o2 : out Test; i : Test) is
>   begin
>      Debug("Setting from", i.a);
>      if o1'Address /= o2'Address then
>         Debug("Setting o1  ", o1.a);
>         Free(o1.a);
>
>         o1.a := new Character'(global);
>         Debug("Setting to1 ", o1.a);
>         global := Character'Succ(global);
>      end if;
>
>      Debug("Setting o2  ", o2.a);
>      Free(o2.a);
>      o2.a := new Character'(i.a.all);
>      Debug("Setting to2 ", o2.a);
>   end Set;
>
>GNA!

This should work.

---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



  reply	other threads:[~2003-07-31 13:15 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
replies disabled

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