comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Extended return question
Date: Thu, 10 Jul 2008 20:43:09 -0400
Date: 2008-07-10T20:43:09-04:00	[thread overview]
Message-ID: <wccabgpqmhu.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 1pdpniur1w9sq$.1a9h7prydviae$.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On Thu, 10 Jul 2008 08:19:41 -0700 (PDT), Adam Beneschan wrote:
>
>> The upshot of this AI is, I think, that (1) the object
>> being worked on for an extended return is *not* an "alias" for the
>> object being created, even for a limited type, and (2) although
>> limited types aren't supposed to be copied, this is true only in an
>> Ada semantic sense, and implementations are allowed to do any block-
>> copies they wish as long as they get the Ada semantics right.
>
> Right, and the position 1 is inconsistent with the notion of limited type.
> A "backdoor" 2 does not save it as the following example illustrates:

I don't see any problem here.  The "notion of limited type" is "do not
copy".  In the example below, X is created, then destroyed, then another
X is created, and that becomes the result.  No copying.

> with Ada.Finalization;
> with Ada.Text_IO;  use Ada.Text_IO;
>
> procedure Test_Return is
>    package Test is
>       type T is
>          new Ada.Finalization.Limited_Controlled with null record;
>       overriding
>          procedure Finalize (X : in out T);
>       overriding
>          procedure Initialize (X : in out T);
>       function Create return T;
>    end Test;
>    
>    package body Test is
>       procedure Finalize (X : in out T) is
>       begin
>          Put_Line ("Finalized");
>       end Finalize;
>       procedure Initialize (X : in out T) is
>       begin
>          Put_Line ("Initialized");
>       end Initialize;
>       function Create return T is
>       begin
>          return X : T do
>             raise Constraint_Error;
>          end return;
>       exception
>          when Constraint_Error =>
>             return X : T;
>       end Create;
>    end Test;
>
>    use Test;
>    X : T := Create;
> begin
>    null;
> end Test_Return;
>
> The output should be:
>
> Initialized
> Finalized
> Initialized
> Finalized

Right.

> This is a case when *a* limited object is initialized and finalized twice,
> which is semantically inconsistent.

No, X is initialized and finalized, then a different X is initialized,
which becomes a still-different X, which is then finalized.

I don't see how that's "semantically inconsistent".

> OK, Initialize is not a constructor. But we could rewrite the above so that
> Create would call itself multiple times over the "same" X before it would
> finally "return" X!

- Bob



  reply	other threads:[~2008-07-11  0:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-10  2:11 Extended return question Dale Stanbrough
2008-07-10  7:18 ` Georg Bauhaus
2008-07-10  7:32   ` Dale Stanbrough
2008-07-10 15:24     ` Adam Beneschan
2008-07-10 23:56       ` Dale Stanbrough
2008-07-10 23:20     ` Randy Brukardt
2008-07-11  0:03       ` Adam Beneschan
2008-07-11  0:50         ` Robert A Duff
2008-07-10 14:37 ` Robert A Duff
2008-07-10 15:19   ` Adam Beneschan
2008-07-10 18:36     ` Dmitry A. Kazakov
2008-07-11  0:43       ` Robert A Duff [this message]
2008-07-11  7:39         ` Dmitry A. Kazakov
2008-07-11  9:06           ` christoph.grein
2008-07-11 14:24             ` Dmitry A. Kazakov
2008-07-11  0:29     ` Robert A Duff
replies disabled

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