comp.lang.ada
 help / color / mirror / Atom feed
From: Mark Johnson <Mark_H_Johnson@Raytheon.com>
Subject: Re: Ada Address = C pointer ?
Date: Tue, 30 Oct 2001 11:10:53 -0600
Date: 2001-10-30T11:10:53-06:00	[thread overview]
Message-ID: <3BDEDF1D.14FE7197@Raytheon.com> (raw)
In-Reply-To: mailman.1004435945.8449.comp.lang.ada@ada.eu.org

"M. A. Alves" wrote:

> [snip]

> 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 ?
>

Reread the implementation advice in B.3....
 An Ada parameter of an array type with component type T, of any mode, is passed
as a t* argument to a C function, where t is the C type corresponding to the Ada
type T.

Of course, your mileage may vary - but here's a simple test case that I ran using
GNAT on Linux....

a.c...
#include <string.h>
void a ( int * x, int * y) {
  memcpy(y, x, 40);
}
b.adb...
with Text_Io;
procedure B is
  type Xt is array (1..10) of Integer;
  Y : Xt := (others => 1);
  Z : Xt := (others => 0);

  procedure A (X : Xt; Y : Xt);
  pragma Import(C, A, "a");

  begin
  A(Y, Z);
  if (Z(1)=1) then
    Text_Io.Put_Line("Ok");
  else
    Text_Io.Put_Line("Failed");
  end if;
end B;

which after being built runs and prints out "Ok".

Good luck.
  --Mark




  parent reply	other threads:[~2001-10-30 17:10 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
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 [this message]
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