comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Initialization and Finalization of limited object "returned" by a function
Date: Thu, 11 Feb 2010 17:05:59 -0800 (PST)
Date: 2010-02-11T17:05:59-08:00	[thread overview]
Message-ID: <a3d5d6c2-cbaa-4ccc-8d3b-46692285ba57@m24g2000prn.googlegroups.com> (raw)
In-Reply-To: 2801be3a-afd6-4d14-ad7f-feb23a511f02@a5g2000yqi.googlegroups.com

On Feb 11, 2:49 pm, Hibou57 (Yannick Duchêne)
<yannick_duch...@yahoo.fr> wrote:
> On 11 fév, 22:51, Adam Beneschan <a...@irvine.com> wrote:> 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
>
> Yes
>
> > (but the anonymous object will be finalized later,
>
> Which anonymous object ?

Any time you call a function, the language semantics say that there is
a "result object" to hold the function result.  The function is called
and puts its result in the result object.  The reason the language
calls it a distinct object is so that it can define when Adjusts and
finalizations take place for this object.

I may have erred by calling it an anonymous object.  In Ada 95, I
believe it was referred to as an anonymous object.  In Ada 2005, if
you use the extended return syntax, this gives a name to the result
object (as Bob said), so maybe it's wrong to call it "anonymous",
although there are parts of the RM that refer to "the anonymous object
representing the result of a function call" or words to that effect.
In any case, at the place where the function is called, you can't
refer to this result object by any name.

My earlier post may have been confusing because I was referring to two
separate parts of the function call process: (1) how the value gets
INTO the result object and (2) what the caller does with the result
object AFTER the function is finished.

For #1, when the function says

   return EXPR;

then EXPR is assigned into the result object (which means that an
Adjust has to be done), *unless* the result object gets built in
place, which is always the case if EXPR is a function call and the
type is limited.  But if the function says

   return NAME : TYPE [do ... end return];

then NAME is a name that *refers* to the result object; NAME does
*not* declare another object that will get assigned to the result
object as in the earlier example.

For #2, if you say

   X : T := Func(...);

The call to Func means that there is a "result object".  When Func is
called, the value gets put into the result object somehow, as
mentioned above.  Then, if X is not built in place, the result object
is copied to X, which means that an Adjust is done, and then the
result object is finalized.  However, if X *is* built in place (as it
must be if T is limited), then the call to Func puts a value into the
result object; and then after that point, X starts "magically"
referring to that result object.  There's no copying, and no
Finalize.  That's what the RM means by "mutating into".  Yes, the
language is a bit weird, and I know it was difficult for the ARG to
find the right words to express what was supposed to happen.

Anyway, the end result of all this is that, for a limited type (or in
any other case where X is built in place), there isn't supposed to be
any finalization until X disappears.  In your case, if you're seeing
your A_Type get finalized while Tested_Interface still exists, this is
incorrect behavior.

Hope this clears things up.  If instead I've just created more
confusion, I apologize and promise to refrain from making things worse
by trying to explain myself any more.

                                     -- Adam




  parent reply	other threads:[~2010-02-12  1:05 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 [this message]
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
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