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 Path: controlnews3.google.com!news1.google.com!news.glorb.com!newsfeed.stueberl.de!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Where are returned values stored? (follow up to yesterday's question) Date: 26 May 2004 21:44:04 +0100 Organization: Pushface Sender: simon@smaug.pushface.org Message-ID: References: <75s9b0pgo91ctvlm5op2rcql82t9ip4me2@4ax.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1085604522 22559 62.49.19.209 (26 May 2004 20:48:42 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Wed, 26 May 2004 20:48:42 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 Xref: controlnews3.google.com comp.lang.ada:867 Date: 2004-05-26T21:44:04+01:00 List-Id: James Alan Farrell writes: > Now its my understanding that when variables are declared like this, > they are added onto the stack, then when the function returns, they > are popped off again, along with the regular stack frame. So the > stuff returned goes away. > > But, the calling function will need use of that data. So it cannot go > away. > > So how does that work? Where is the data placed so that it does not > go away, and how long will it be there so it (or rather pointers to > it) can be passed around to other functions? The simple answer is that it returns a copy of the data, just like simple variables .. int foo() { // stuff { int res; // stuff return res; } return 3; } There may be a more complicated, implementation-dependent answer involving secondary stacks, but I see no reason in the language why you need the concept of pointer in this context. And, however it works, it will be stack-based, so the data will go away at some point as the stack is popped. -- Simon Wright 100% Ada, no bugs.