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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!l34g2000vba.googlegroups.com!not-for-mail From: Mike Newsgroups: comp.lang.ada Subject: calling ada from c with an array param Date: Sun, 20 Sep 2009 12:38:04 -0700 (PDT) Organization: http://groups.google.com Message-ID: <0208bf86-cba9-45db-a43c-53c249bf9ae6@l34g2000vba.googlegroups.com> NNTP-Posting-Host: 157.127.124.15 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1253475485 30658 127.0.0.1 (20 Sep 2009 19:38:05 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 20 Sep 2009 19:38:05 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l34g2000vba.googlegroups.com; posting-host=157.127.124.15; posting-account=75iYsQoAAABUEoLZrxFNnZsTxbZSb5pV User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8409 Date: 2009-09-20T12:38:04-07:00 List-Id: I'm new to Ada so I'm trying to expand a simple c example that passed primitive types to an Ada function. I'm trying to call an ada procedure from a c program with an in out float array using GNAT. I read you should not use an unconstrained array so I tried the following The c program is #include #include #include extern void adainit (void); extern void adafinal (void); extern int conjunc (float[], int); int main (int argc, char *argv[]) { int i; float b[3] = {0.0, 0.0, 0.0}; adainit(); conjunc(a, 4); for (i = 0; i < 3; i++) { printf("a[%d] = %f, b[%d] = %f\n", i, a[i], b[i]); } adafinal(); } The .ads file is -- conjunc.ads package conjunc is type Float_Array is array (Integer range <>) of Float; subtype Contrained_Float_Array is Float_Array (1 .. Integer'Last); procedure conj (A: in out Constrained_Float_Array; Len: in Integer); pragma Export (C, conj, "conj"); end conjunc; and the procedure .adb file is -- conjunc.adb package body conjunc is type Float_Array is array (Integer range <>) of Float; subtype Contrained_Float_Array is Float_Array (1 .. Integer'Last); procedure conj (A: in out Constrained_Float_Array; Len :in Integer) is begin A(1) := 99; A(2) := 100; A(3) := 101; A(4) := 102; end conj; end conjunc; The procedure to build it is first gcc -c cjserver.c which works fine, then gnatmake -c conjunc.adb which gives me the following error: conjunc.adb:3:09: "Float_Array" conflicts with declaration at conjunc.ads:3 conjunc.adb:4:12: "Contrained_Float_Array" conflicts with declaration at conjunc.ads:4 conjunc.ads:5:30: "Constrained_Float_Array" is undefined (more references follow) conjunc.ads:5:30: possible misspelling of "Contrained_Float_Array" Obviously there is a problem declaring the array, but I'm not sure where it goes. Can someone help? Thanks Mike