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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a71fc4911021ed50 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail From: igor.kh@gmail.com Newsgroups: comp.lang.ada Subject: Re: Returning data from Ada to C Date: 7 May 2005 15:12:07 -0700 Organization: http://groups.google.com Message-ID: <1115503927.228956.100050@z14g2000cwz.googlegroups.com> References: <1115164192.585409.163780@z14g2000cwz.googlegroups.com> <9vYde.5480$GQ5.3731@newsread1.news.pas.earthlink.net> <4f1a9$4278d210$cf702d0d$18288@PRIMUS.CA> NNTP-Posting-Host: 129.100.144.139 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1115503931 12036 127.0.0.1 (7 May 2005 22:12:11 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 7 May 2005 22:12:11 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=129.100.144.139; posting-account=yKC4HgwAAABh06UMMZG_tyXZIoZug5Yj Xref: g2news1.google.com comp.lang.ada:10948 Date: 2005-05-07T15:12:07-07:00 List-Id: Jeffrey Carter wrote: > Igor Khavkine wrote: > > Great! Now, what type will `Solvec' have? I presume that GNAT will > > bark at me if I use the wrong type. > > In Ada, it's a pointer to Double; to C it should look like a pointer > to double. You probably should declare your array type to be > convention C, just to be on the safe side. I've tried to construct a simple example where this would work. However, I am still failing. I can't get the types to match up. Below are the files that I'm using. The exact error from gnat is: hello_world.adb:18:19: expected type "Interfaces.C.Pointers.Pointer" from instance at c_integer_arrays.ads:6 == c_integer_arrays.ads ================ with Interfaces.C; use Interfaces.C; with Interfaces.C.Pointers; package C_Integer_Arrays is type C_Integer_Array is array (size_t range <>) of aliased int; package C_IntArrs is new Interfaces.C.Pointers(size_t, int, C_Integer_Array, 0); end C_Integer_Arrays; ======================================== == hello_world.ads ===================== with Interfaces.C; use Interfaces.C; with C_Integer_Arrays; use C_Integer_Arrays; procedure Hello_World ( i : in out integer; a_ptr : out C_IntArrs.Pointer ); pragma Export (C, Hello_World); ======================================== == hello_world.adb ===================== with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Interfaces.C; use Interfaces.C; with C_Integer_Arrays; use C_Integer_Arrays; procedure Hello_World ( i : in out integer; a_ptr : out C_IntArrs.Pointer ) is a : aliased array(0..2) of int; pragma Convention (C, a); begin Put ("Hello world!"); Put (i); i := 10; a(0) := 3; a(1) := 2; a(2) := 1; a_ptr := a'Unchecked_Access; end Hello_World; ======================================== == hello.c ============================= #include void adainit(); void adafinal(); void hello_world(int *i, int **a_ptr); int main() { int i = 1; int *a_ptr; printf ("Calling Ada...\n"); adainit(); hello_world(&i, &a_ptr); printf ("...done\n"); printf ("Returned i = %d\n", i); for (i=0; i<3; i++) printf ("a_ptr[%d] = %d\n", i, a_ptr[i]); adafinal(); return 0; } ======================================== What am I missing to make this work? Thanks in advance. Igor