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!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Where are returned values stored? (follow up to yesterday's question) Date: Thu, 27 May 2004 09:51:52 +0200 Message-ID: References: <75s9b0pgo91ctvlm5op2rcql82t9ip4me2@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de NNwpVW38HyhZZCWQzug21wCP5sq917D4L2qZiHg096feAFL2g= X-Newsreader: Forte Agent 1.8/32.548 Xref: controlnews3.google.com comp.lang.ada:873 Date: 2004-05-27T09:51:52+02:00 List-Id: On 26 May 2004 21:44:04 +0100, Simon Wright wrote: >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 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