From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,984d3d7860d7c8c X-Google-Attributes: gid103376,public From: James Alan Farrell Newsgroups: comp.lang.ada Subject: Re: Where are returned values stored? Date: Thu, 27 May 2004 16:24:06 -0400 Message-ID: References: <75s9b0pgo91ctvlm5op2rcql82t9ip4me2@4ax.com> <1dptc.49822$tb4.1731604@news20.bellglobal.com> X-Newsreader: Forte Free Agent 2.0/32.652 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: fw.grammatech.com X-Trace: newsfeed.slurp.net 1085689514 209.4.89.67 (27 May 2004 15:25:14 -0500) X-Original-NNTP-Posting-Host: 209.4.89.67 Path: controlnews3.google.com!news1.google.com!news.glorb.com!cyclone1.gnilink.net!gnilink.net!peer01.cox.net!cox.net!newsfeed.slurp.net!not-for-mail Xref: controlnews3.google.com comp.lang.ada:886 Date: 2004-05-27T16:24:06-04:00 List-Id: 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" 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.