comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Initialization and Finalization of limited object "returned" by a function
Date: Thu, 11 Feb 2010 17:53:13 -0500
Date: 2010-02-11T17:53:13-05:00	[thread overview]
Message-ID: <wcc8waziduu.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 75a9f860-ad3c-49a0-b2a1-a8f1386e6ff6@x10g2000prk.googlegroups.com

Adam Beneschan <adam@irvine.com> writes:

> On Feb 11, 11:10�am, Robert A Duff <bobd...@shell01.TheWorld.com>
> wrote:
>> Adam Beneschan <a...@irvine.com> writes:
>> > But more simply, as I understand it: (1) When you have an extended
>> > return, the return object is used as the anonymous object that holds
>> > the function result at the point of the function call, so it's not
>> > finalized until the caller is done with the anonymous object; and (2)
>> > when the object is built in place, the anonymous object "mutates into"
>> > the new object and is not finalized (7.6(17.7/3)). �So yes, no
>> > finalization should be done until X goes out of scope.
>>
>> Just to be clear: There's nothing particularly special about
>> extended return statements, other than the fact that they
>> provide a name for the result. �
>
> That last is an important distinction, however.  A function call
> involves (conceptually) an anonymous object.  For a normal return (for
> a non-limited type):
>
>    return Some_Expression;
>
> Some_Expression is computed and then assigned into the anonymous
> object.  This assignment involves an Adjust.  Then, at some point,
> whatever objects went into creating Some_Expression will get finalized
> when the function exits.  If Some_Expression is a local variable, for
> instance, that variable will get finalized.  If some other temporary
> needs to be created in order to hold the value of Some_Expression,
> that temporary will be finalized.

That's right for nonlimited types, but my point is that it is
not right for limited types.

For limited types, "return Some_Expression;" and
"return Result : constant T := Some_Expression;"
have identical effect.  Adjust is not called (there is no
Adjust in the limited case), and the result object
is not finalized when leaving the function.

Note that in the limited case, Some_Expression cannot
be the name of a local variable -- it can be a function
call or an aggregate.

So we can have a whole chain of calls.  E.g.:

    X : T := A(...); -- T is limited

and A says "return B(...);", and B says "return C(...);"
and C says "return T'(agg, reg, ate);" -- there's only
one result object.  The aggregate inside C is built directly
in variable X.  It is not finalized when leaving C, B, or A.

> For an extended return,
>
>    return R : T;

> R is not a local variable, and it isn't "assigned" into the anonymous
> object; thus, there's no Adjust, and R is not finalized when the
> function returns (but the anonymous object will be finalized later,
> except when it mutates into some other object).  I think that's the
> point of the nasty language in 3.10.2(10.1).  Which is another way of
> saying that R is a name for the result (as you said), not a distinct
> object that gets copied to the result.

It doesn't matter whether the result object has a name or not.
What matters is whether it's limited -- in the limited case,
the result object is NOT finalized when leaving the function.

>...I thought it would be helpful
> to point it out---not to you, but to other readers.  It's hardly a
> trivial difference, and it's an important one to understand when
> adjusts and finalizations are involved.  Anyway, I hope this helps
> someone.

Well, umm...  ;-)

- Bob



  parent reply	other threads:[~2010-02-11 22:53 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-11  4:37 Initialization and Finalization of limited object "returned" by a function Hibou57 (Yannick Duchêne)
2010-02-11  9:51 ` Hibou57 (Yannick Duchêne)
2010-02-11 11:00 ` Ludovic Brenta
2010-02-11 11:33   ` Jean-Pierre Rosen
2010-02-11 23:15   ` Hibou57 (Yannick Duchêne)
2010-02-11 23:24     ` Robert A Duff
2010-02-12  5:41       ` Hibou57 (Yannick Duchêne)
2010-02-12 15:15         ` Robert A Duff
2010-02-12 16:27           ` Jean-Pierre Rosen
2010-02-12 17:53             ` Jacob Sparre Andersen
2010-02-12 18:05               ` Adam Beneschan
2010-02-13  1:59             ` Randy Brukardt
2010-02-12 16:57           ` Adam Beneschan
2010-02-12 18:07             ` mockturtle
2010-02-12 18:29               ` Hibou57 (Yannick Duchêne)
2010-02-12 19:09             ` Robert A Duff
2010-02-13  2:00               ` Randy Brukardt
2010-02-13  2:51                 ` Hibou57 (Yannick Duchêne)
2010-02-13 15:59                   ` Robert A Duff
2010-02-13 19:34                     ` Hibou57 (Yannick Duchêne)
2010-02-13 19:45                       ` Robert A Duff
2010-02-12 19:10             ` (see below)
2010-02-13  9:54           ` Dmitry A. Kazakov
2010-02-13 15:52             ` (see below)
2010-02-14 10:23               ` Dmitry A. Kazakov
2010-02-13 15:53             ` Robert A Duff
2010-02-14 10:59               ` Dmitry A. Kazakov
2010-02-14 22:00                 ` Hibou57 (Yannick Duchêne)
2010-02-11 15:16 ` Robert A Duff
2010-02-11 17:40   ` Adam Beneschan
2010-02-11 19:10     ` Robert A Duff
2010-02-11 21:51       ` Adam Beneschan
2010-02-11 22:49         ` Hibou57 (Yannick Duchêne)
2010-02-11 22:53           ` Hibou57 (Yannick Duchêne)
2010-02-11 23:08             ` Robert A Duff
2010-02-11 23:18               ` Hibou57 (Yannick Duchêne)
2010-02-12  0:48               ` Randy Brukardt
2010-02-12  5:37               ` Hibou57 (Yannick Duchêne)
2010-02-13  1:54                 ` Randy Brukardt
2010-02-12  5:39               ` Hibou57 (Yannick Duchêne)
2010-02-12 15:10                 ` Robert A Duff
2010-02-12 17:15                   ` (Hibou57) Yannick Duchêne
2010-02-12 19:07                     ` Robert A Duff
2010-02-12  1:05           ` Adam Beneschan
2010-02-12  2:35             ` Hibou57 (Yannick Duchêne)
2010-02-12  2:36               ` Hibou57 (Yannick Duchêne)
2010-02-12  2:36               ` Hibou57 (Yannick Duchêne)
2010-02-12  2:36               ` Hibou57 (Yannick Duchêne)
2010-02-12  2:37               ` Hibou57 (Yannick Duchêne)
2010-02-12  2:37               ` Hibou57 (Yannick Duchêne)
2010-02-12  2:37               ` Hibou57 (Yannick Duchêne)
2010-02-12  4:27                 ` Hibou57 (Yannick Duchêne)
2010-02-12  4:28                   ` Hibou57 (Yannick Duchêne)
2010-02-11 22:53         ` Robert A Duff [this message]
2010-02-11 23:41           ` Adam Beneschan
2010-02-12  0:22             ` Robert A Duff
2010-02-12  5:25         ` Hibou57 (Yannick Duchêne)
2010-02-12  9:27         ` Alex R. Mosteo
2010-02-12 16:43           ` Adam Beneschan
2010-02-12 19:11             ` Robert A Duff
2010-02-12  0:44     ` Randy Brukardt
2010-02-12  4:47     ` Hibou57 (Yannick Duchêne)
2010-02-12 18:02       ` Adam Beneschan
2010-02-12  4:49     ` Hibou57 (Yannick Duchêne)
2010-02-12  4:40   ` Hibou57 (Yannick Duchêne)
replies disabled

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