comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Where are returned values stored? (follow up to yesterday's question)
Date: 26 May 2004 21:44:04 +0100
Date: 2004-05-26T21:44:04+01:00	[thread overview]
Message-ID: <x7vpt8qly0b.fsf@smaug.pushface.org> (raw)
In-Reply-To: 75s9b0pgo91ctvlm5op2rcql82t9ip4me2@4ax.com

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 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.



  reply	other threads:[~2004-05-26 20:44 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 [this message]
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
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