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,start X-Google-Attributes: gid103376,public From: James Alan Farrell Newsgroups: comp.lang.ada Subject: Where are returned values stored? (follow up to yesterday's question) Date: Wed, 26 May 2004 15:46:21 -0400 Message-ID: <75s9b0pgo91ctvlm5op2rcql82t9ip4me2@4ax.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 1085600849 209.4.89.67 (26 May 2004 14:47:29 -0500) X-Original-NNTP-Posting-Host: 209.4.89.67 Path: controlnews3.google.com!news1.google.com!news.glorb.com!news.moat.net!newsfeed.slurp.net!not-for-mail Xref: controlnews3.google.com comp.lang.ada:865 Date: 2004-05-26T15:46:21-04:00 List-Id: Hello again, This is a followup to the question I asked yesterday. Below is a bit of code from GNAT's ASIS library. (I imagine this was written by people with a lot more expertise in Ada than I have, and that this code is okay.) It has a declarative part in the middle of the code, in which a variable (Result) is declared. The stuff in that variable is returned. 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? (This relates to yesterday's question because if this works the code I posted yesterday ought to work) Thanks again, James Alan Farrell GrammaTech function Compilation_Units (The_Context : in Asis.Context) return Asis.Compilation_Unit_List is Res_Cont_Id : Context_Id := Get_Cont_Id (The_Context); Cont_Tree_Mode : Tree_Mode; begin Check_Validity (The_Context, "Asis.Compilation_Units.Compilation_Units"); Cont_Tree_Mode := Tree_Processing_Mode (Res_Cont_Id); if not (Cont_Tree_Mode = Pre_Created or else Cont_Tree_Mode = Incremental) then Not_Implemented_Yet (Diagnosis => "Asis.Compilation_Units.Compilation_Units"); end if; Reset_Context (Res_Cont_Id); declare Result_Len : Natural := Lib_Unit_Decls (Res_Cont_Id) + Comp_Unit_Bodies (Res_Cont_Id); Result : Compilation_Unit_List (1 .. Result_Len); begin for I in 1 .. Result_Len loop Result (I) := Get_Comp_Unit (First_Unit_Id + Unit_Id (I) - 1, Res_Cont_Id); end loop; return Result; end; exception when ASIS_Failed => Add_Call_Information (Outer_Call => "Asis.Compilation_Units.Compilation_Units"); raise; when others => Raise_ASIS_Failed (Diagnosis => "Asis.Compilation_Units.Compilation_Units"); end Compilation_Units;