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,start 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: Returning data from Ada to C Date: 3 May 2005 16:49:52 -0700 Organization: http://groups.google.com Message-ID: <1115164192.585409.163780@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: 129.100.144.139 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1115164197 26118 127.0.0.1 (3 May 2005 23:49:57 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 3 May 2005 23:49:57 +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:10902 Date: 2005-05-03T16:49:52-07:00 List-Id: I want to make use of an Ada package from some C code. I already have something that does almost what I want, but I need to figure out how to return some data from Ada to C. I've never worked with Ada before, so please pardon my ignorance. Here's the setup. I have a C file: ---- main.c ---- #include extern void adainit(); extern void adafinal(); extern void _ada_phc_direct_solver ( ..., int *rcnt, double **solvec ); int main () { int rcnt; double *solvec; int i, j, n; /* Do some initializations. */ ... /* I want the Ada code to store a pointer in `solvec'. */ adainit(); _ada_phc_direct_solver(..., &rcnt, &solvec); adafinal(); /* BTW, is it OK to use Ada allocated memory after `adafinal()'? */ /* Print results. */ printf ("Root count: %d\n", rcnt); printf ("Roots: Re Im\n"); for (i=0; i ) of aliased Interfaces.C.double; -- -- package C_DblArrs is -- new Interfaces.C.Pointers(Interfaces.C.size_t, -- Interfaces.C.double, -- C_Double_Array,0.0); -- -- Perhaps I should be using another type, but I don't know which one. rc : integer; sols : C_Double_Array; -- This is probably wrong, but `sols' will be -- a C_Double_Array of some size. begin -- Calculate `rc' and `sols'. ... -- Now I want to return `rcnt' and `sols' rcnt := rc; -- This is the easy part. solvec := ??? -- What goes here? end phc_direct_solver; ------------------------------- Basically, the Ada code creates an array which I want pass back to the C code through a pointer. Unfortunately, I'm not familiar enough with Ada figure out how to do that. Any help or suggestions would be appreciated. A related question. I'm using GNAT as the compiler. I read the section in the documentation about linking a main C program with Ada auxiliary Ada code. But it looks like the linking can only be done with gnatlink at the final stage, when the executable is created. Is there a way to compile the Ada code directly into a .o or .so object file that can be linked normally with gcc? Thanks in advance. Igor P.S.: For those who are curious, I'm trying to make use of PHCpack[1] to solve a system of polynomial equations. I'm working from the existing example ts_phc_solver.c. [1] http://www2.math.uic.edu/~jan/download.html