comp.lang.ada
 help / color / mirror / Atom feed
From: Mike <michael_tabak@yahoo.com>
Subject: calling ada from c with an array param
Date: Sun, 20 Sep 2009 12:38:04 -0700 (PDT)
Date: 2009-09-20T12:38:04-07:00	[thread overview]
Message-ID: <0208bf86-cba9-45db-a43c-53c249bf9ae6@l34g2000vba.googlegroups.com> (raw)

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 <stdio.h>
#include <stdlib.h>
#include <string.h>

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



             reply	other threads:[~2009-09-20 19:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-20 19:38 Mike [this message]
2009-09-20 19:59 ` calling ada from c with an array param Jan Andres
2009-09-21  8:04 ` Dmitry A. Kazakov
2009-09-21  8:08   ` Dmitry A. Kazakov
2009-09-21 17:29 ` Jeffrey R. Carter
2009-09-21 19:58 ` sjw
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox