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,68b2e2c0309a6e88 X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news1.google.com!news.glorb.com!lon-transit.news.telstra.net!lon-spool.news.telstra.net!lon-in.news.telstra.net!news.telstra.net!news-server.bigpond.net.au!53ab2750!not-for-mail From: Dale Stanbrough Newsgroups: comp.lang.ada Subject: Re: Question on interface Ada to C References: User-Agent: MT-NewsWatcher/3.4 (PPC Mac OS X) Message-ID: Date: Tue, 25 May 2004 21:30:34 GMT NNTP-Posting-Host: 138.217.31.119 X-Complaints-To: abuse@bigpond.net.au X-Trace: news-server.bigpond.net.au 1085520634 138.217.31.119 (Wed, 26 May 2004 07:30:34 EST) NNTP-Posting-Date: Wed, 26 May 2004 07:30:34 EST Organization: BigPond Internet Services Xref: controlnews3.google.com comp.lang.ada:832 Date: 2004-05-25T21:30:34+00:00 List-Id: James Alan Farrell wrote: > Thanks, > James Alan Farrell > GrammaTech. > > type stuff is integer; -- just for example > > type List_Type is array(Integer range <>) of stuff; > > package MyPointers is > new System.Address_To_Access_Conversions(List_Type); > subtype List_Pointer is MyPointers.Object_Pointer; > > procedure MyProc > (Items : in out List_Pointer; > Nitems : in out Integer) is > > List : List_Type := function_that_returns_a_list; > > begin > Nitems := List'Length; > Items := MyPointers.To_Pointer(List'Address); > end; You are right in thinking it is not good code. The variable List is allocated on the stack/secondary head, and should go away when the procedure ends. The pointer to it will no longer be valid once you return from this procedure. Better to have function_that_returns_a_list be function_that_returns_a_pointer_to_a_list and return that.... type List_Type_Access is access all List_Type; -- declare this type where it is visible to your -- other function. List_Ptr :+ list_type_access := function_that_returns_a_pointer... begin Nitems := List.all'Length; Items := MyPointers.To_Pointer(List.all(1)'Address); end; there's probably other stuff you should look at in the Interfaces.C.* package family - there will be a better way than this. Dale -- dstanbro@spam.o.matic.bigpond.net.au