comp.lang.ada
 help / color / mirror / Atom feed
From: James Alan Farrell <anonymous@anonymous.com>
Subject: Re: Where are returned values stored?
Date: Thu, 27 May 2004 16:24:06 -0400
Date: 2004-05-27T16:24:06-04:00	[thread overview]
Message-ID: <fgjcb0pnsbdcaadc3j365f3ld13m42aaf8@4ax.com> (raw)
In-Reply-To: 1dptc.49822$tb4.1731604@news20.bellglobal.com

Interesting to consider this with a recursive procedure, but yes, it
should work.

JAF

On Thu, 27 May 2004 13:05:06 -0400, "Warren W. Gay VE3WWG"
<ve3wwg@cogeco.ca> wrote:

>
>Conceptually, there is _no_ reason a compiler _must_ copy a
>return value. Consider a function like:
>
>function Foo return String is
>   I : Integer := 23;
>   S : String(1..3) := "Bar";
>   X : Natural := 0;
>begin
>   ...
>   return S;
>end;
>
>To return S, all the compiler needs to do is to extend the
>caller's stack frame to claim all the storage up to and
>including S (I and S assuming sequential assignment), at
>the point when Foo returns (return effectively does
>reclaim the storage used for X however).
>
>Then the calling code can reference S as if it were a
>local variable.  The space used for I is
>wasted at this point, but temporarily, who cares?
>
>Once the compiler knows that the caller's use of the returned
>value S is no longer required, the stack frame can be shrunk
>back to the original size that it had prior to calling Foo.
>
>Is this done? Is it done by GNAT? I have no idea, but I
>suspect that this is done in some places, some of the time,
>by some compilers. Perhaps, someone in this group
>can confirm/debunk this idea.




  reply	other threads:[~2004-05-27 20:24 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-26 19:46 Where are returned values stored? (follow up to yesterday's question) James Alan Farrell
2004-05-26 20:44 ` Simon Wright
2004-05-27  7:51   ` Dmitry A. Kazakov
2004-05-27  9:39 ` Where are returned values stored? Marius Amado Alves
2004-05-27 17:05   ` Warren W. Gay VE3WWG
2004-05-27 20:24     ` James Alan Farrell [this message]
2004-05-28 20:33       ` Warren W. Gay VE3WWG
2004-05-29  7:03         ` Martin Krischik
2004-05-29 13:19           ` Larry Kilgallen
2004-05-30  7:10             ` Martin Krischik
2004-06-02  3:14         ` Robert I. Eachus
2004-05-30 21:17     ` Nick Roberts
2004-05-31 12:58       ` Warren W. Gay VE3WWG
2004-06-02  4:07         ` Robert I. Eachus
2004-06-02 12:42           ` Warren W. Gay VE3WWG
2004-06-03  2:00             ` Nick Roberts
2004-06-03  4:34             ` Robert I. Eachus
2004-06-03 16:06               ` Warren W. Gay VE3WWG
2004-06-03 16:13               ` Nick Roberts
2004-06-07  1:53                 ` Robert I. Eachus
2004-06-07 13:09                   ` Larry Kilgallen
2004-06-09  7:03                     ` Robert I. Eachus
2004-06-05 17:13             ` Simon Wright
2004-05-27 17:11   ` Martin Krischik
2004-05-27 17:07 ` Where are returned values stored? (follow up to yesterday's question) Martin Krischik
replies disabled

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