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-Thread: 103376,490da20402ced2bf X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!newsfeed.stueberl.de!news-mue1.dfn.de!news-ber1.dfn.de!news.uni-hamburg.de!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: dynamic array as return value? Date: Fri, 15 Oct 2004 16:36:09 +0000 (UTC) Organization: GMUGHDU Message-ID: References: NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1097858169 29695 134.91.1.34 (15 Oct 2004 16:36:09 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Fri, 15 Oct 2004 16:36:09 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: g2news1.google.com comp.lang.ada:5275 Date: 2004-10-15T16:36:09+00:00 List-Id: bubble wrote: : return spaceStr; --can I do it? yes : function makeSpaceString(length:Natural) return String is : : spaceStr :string(1..length) := (others => ' '); : : begin : : return spaceStr; --- ??? yes : my question is about memory allocation in ada95. : : I remember,local variable memory allocate should use stack not heap memory. : In above 2 functions. : the variable spaceStr are local variable in function,right? yes : after execute end of function,data in stack memory should free to system. before this happens, the returned value is used in an expression, for example, spaces := makeSpaceString(20); -- copies result to spaces or if my_spaces = makeSpaceString(15) then ... "=" is a function of two arguments, the above could also be written as if "="(my_spaces, makeSpaceString(15)) then ... I suggest that you look at what the compiler produces for such a call. : it mean I return a data in stack and it is free,it will occure illegal : access? In Ada case you can be pretty sure that returning will work no matter what the type is, or else the compiler will tell you you can't do this, for example if you try to return a pointer to a local scalar variable. But return some_string; is not necessarily returning a pointer. -- Georg