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 19:22:16 -0500
Date: 2010-02-11T19:22:16-05:00	[thread overview]
Message-ID: <wcceikrgv5z.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 22770615-78cf-43eb-a817-0af52ddece6a@w27g2000pre.googlegroups.com

Adam Beneschan <adam@irvine.com> writes:

> On Feb 11, 2:53�pm, Robert A Duff <bobd...@shell01.TheWorld.com>
> wrote:
>
>> 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.
>
> But that's true even if it's nonlimited, right?

Well, sort of.  In the nonlimited case, the result object
is copied somewhere, with adjust, and then finalized.
Except that the compiler is allowed to optimize that
away in some cases.  In the limited case, it must not
finalize the result object.

>...If NLT is non-
> limited, and you say (inside function NLT_Func)
>
>    return X : NLT do
>      X.Component := ...
>    end return;
>
> X, which is now another name for the "anonymous result object" created
> for the function call, is not finalized "when leaving the function".
> It's finalized later.  If you say
>
>    Y : NLT := NLT_Func(...);
>
> it's finalized after being copied to Y (assuming it is not built in
> place).

Yeah, OK, but "when leaving the function" and "after copying to Y"
are pretty much the same time.  And "when Y is finalized" is
a very-much-later time.

The finalization rules would be the same if the above return were

    return X : NLT := (Component => ..., others => <>);

or:

    return (Component => ..., others => <>);

My point was just that the "build in place" requirement is invoked by
limitedness, not by the syntax of the return statement.

By the way, I have on my "to do" list to implement build-in-place
in GNAT for NON-limited types, when possible.  That's just an
optimization.

>...If you pass the result to some other function(s):
>
>    Z : Type2 := Func2 (Func3 (NLT_Func (...)));
>
> then I believe the result object (of NLT_Func) is not finalized until
> after the entire expression is evaluated, right?

I don't remember the exact rules in this case.  As you say,
they're "nasty".  ;-)

- Bob



  reply	other threads:[~2010-02-12  0:22 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
2010-02-11 23:41           ` Adam Beneschan
2010-02-12  0:22             ` Robert A Duff [this message]
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