From: Dale Stanbrough <MrNoSpam@bigpoop.net.au>
Subject: Re: Question on interface Ada to C
Date: Tue, 25 May 2004 21:30:34 GMT
Date: 2004-05-25T21:30:34+00:00 [thread overview]
Message-ID: <MrNoSpam-914321.07303326052004@news-server.bigpond.net.au> (raw)
In-Reply-To: rac7b0tnlsoauhcharlguhr7v3g30npk6b@4ax.com
James Alan Farrell <anonymous@anonymous.com> 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
next prev parent reply other threads:[~2004-05-25 21:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-25 21:00 Question on interface Ada to C James Alan Farrell
2004-05-25 21:30 ` Dale Stanbrough [this message]
2004-05-25 21:38 ` Simon Wright
2004-05-26 10:23 ` Dale Stanbrough
2004-05-26 13:05 ` James Alan Farrell
2004-05-26 16:01 ` Martin Krischik
2004-05-26 7:34 ` 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