comp.lang.ada
 help / color / mirror / Atom feed
From: lutz@iks-jena.de (Lutz Donnerhacke)
Subject: Re: Ada Address = C pointer ?
Date: Tue, 30 Oct 2001 12:02:16 +0000 (UTC)
Date: 2001-10-30T12:02:16+00:00	[thread overview]
Message-ID: <slrn9tt5m8.f2n.lutz@belenus.iks-jena.de> (raw)
In-Reply-To: mailman.1004435945.8449.comp.lang.ada@ada.eu.org

* M. A. Alves wrote:
>I am in fact using Address and Access_To_Address_Conversions(*) because I
>simply did not find out how to do the trick otherwise.  For example, the C
>function is returning an array of unsigned long.  I want to access that
>array without copying it.  How can you do that with Interfaces.C.Strings
>or even Interfaces.C.Pointers?

How about:

with Interfaces.C.Pointers;

procedure t is
   type long_array is array (Integer range <>) of aliased Interfaces.C.long;
   
   package long_pointers is new Interfaces.C.Pointers (
     Index              => Integer,
     Element            => Interfaces.C.long,
     Element_Array      => long_array,
     Default_Terminator => 0
   );
   
   function get (a : long_pointers.Pointer; i : Interfaces.C.ptrdiff_t)
     return Interfaces.C.long is
     
      use type long_pointers.Pointer;
      
      v : long_array (1 .. 1) :=
        long_pointers.Value (a + i, Interfaces.C.ptrdiff_t (1));
   begin
      return v (1);
   end get;
   pragma Inline (get);
   
   --  real work starts here
   
   function get_long_array return long_pointers.Pointer;
   pragma Import (C, get_long_array);
   
   my_array : constant long_pointers.Pointer := get_long_array;
begin
   ... := get (my_array, 4);
end t;




  reply	other threads:[~2001-10-30 12:02 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-26 18:53 Ada Address = C pointer ? M. A. Alves
2001-10-26 18:09 ` Lutz Donnerhacke
2001-10-26 21:06   ` Florian Weimer
2001-10-26 19:34 ` Mark Johnson
2001-10-26 23:39   ` tmoran
2001-10-29 13:07     ` M. A. Alves
2001-10-29 20:19       ` Matthew Heaney
2001-10-29 23:15         ` tmoran
2001-10-30 10:30           ` M. A. Alves
2001-10-30 19:53             ` tmoran
2001-10-31 13:01               ` M. A. Alves
2001-10-31 14:44                 ` Marin David Condic
2001-10-30  9:58         ` M. A. Alves
2001-10-30 12:02           ` Lutz Donnerhacke [this message]
2001-10-30 12:53             ` M. A. Alves
2001-10-30 12:56               ` Lutz Donnerhacke
2001-10-30 14:26                 ` M. A. Alves
2001-10-30 14:19               ` Matthew Heaney
2001-10-30 14:41                 ` M. A. Alves
2001-10-30 17:10           ` Mark Johnson
2001-10-30 18:01             ` M. A. Alves
2001-10-30 20:23               ` tmoran
2001-10-31 13:13                 ` M. A. Alves
2001-10-30 19:53           ` tmoran
2001-10-29 23:15       ` tmoran
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox