From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: Where are returned values stored? (follow up to yesterday's question)
Date: Thu, 27 May 2004 09:51:52 +0200
Date: 2004-05-27T09:51:52+02:00 [thread overview]
Message-ID: <a77bb0t87pqq7l9ph1kl69v9j77qqgngvn@4ax.com> (raw)
In-Reply-To: x7vpt8qly0b.fsf@smaug.pushface.org
On 26 May 2004 21:44:04 +0100, Simon Wright <simon@pushface.org>
wrote:
>James Alan Farrell <anonymous@anonymous.com> 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 is an exception for limited types. They can be returned as well!
So the following is legal:
type X is limited record ...
A : X;
function Foo return X is
begin
return A;
end Foo;
Here no copy happens upon return.
>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.
--
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de
next prev parent reply other threads:[~2004-05-27 7:51 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 [this message]
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
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