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-Thread: a07f3367d7,e39fb6aac207c1a4 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Jan Andres Newsgroups: comp.lang.ada Subject: Re: calling ada from c with an array param Date: Sun, 20 Sep 2009 21:59:02 +0200 Organization: T-Online Message-ID: References: <0208bf86-cba9-45db-a43c-53c249bf9ae6@l34g2000vba.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.t-online.com 1253476742 01 n565 28CzQWNOpfNeN25 090920 19:59:02 X-Complaints-To: usenet-abuse@t-online.de X-ID: TWS-Y6ZFretGQTA+rSlHFmAUCXtfMolOT-I8lzeuSuTskh89srIo40 User-Agent: slrn/0.9.9p1 (Linux) Xref: g2news2.google.com comp.lang.ada:8410 Date: 2009-09-20T21:59:02+02:00 List-Id: On 2009-09-20, Mike wrote: > 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 All declarations from the package spec (.ads file) are automatically visible in the package body (.adb file), so there's no point in repeating them there. And, unlike C in some cases, Ada generally does not allow repeated declarations of the same entity even if they are equivalent. > conjunc.ads:5:30: "Constrained_Float_Array" is undefined (more > references follow) > conjunc.ads:5:30: possible misspelling of "Contrained_Float_Array" It's true -- there is a typo (missing 's'). HTH Jan -- Jan Andres