From: jerry@jvdsys.nextjk.stuyts.nl (Jerry van Dijk)
Subject: Re: ada routine reading c data problem
Date: 1997/04/05
Date: 1997-04-05T00:00:00+00:00 [thread overview]
Message-ID: <860206044.12snx@jvdsys.nextjk.stuyts.nl> (raw)
In-Reply-To: 33441A45.454D@ny.essd.northgrum.com
>I am running on a WINNT pc using gnat. I have a program that has both
>ada and c modules. I need to be able to access the c structures from
>the ada code. Is there any way of doing this besides a special c
>routine to send back the data.
Yes, if the structures are accesible according to C rules you can define
the struct in Ada and import the actual instantiations. In GNAT this
couldn't be simpler:
/* c.c */
#include <stdio.h>
struct a_struct {
int a;
float b;
} var_a;
void display_struct(void)
{
printf("Struct values are: a -> %d, b -> %f\n", var_a.a, var_a.b);
}
-- test.adb
procedure Test is
type A_Struct is
record
A : Integer;
B : Float;
end record;
Var_A : A_Struct;
pragma Import (C, Var_A);
procedure Display_Struct;
pragma Import (C, Display_Struct);
begin
Var_A.a := 1;
Var_A.b := 2.0;
Display_Struct;
end Test;
to test:
gcc -c c.c
gcc -c test.adb
gnatbind -x test.ali
gnatlink test.ali c.o
Note that depending on the struct you might have to pack items or the stuct,
in using it as an argument, you might run into copy by reference vs copy by
value issues. See the GNAT user manual for more details.
--
-- Jerry van Dijk | Haarlem, Holland
-- Business Consultant | Team Ada
-- Ordina Finance | jdijk@acm.org
prev parent reply other threads:[~1997-04-05 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-04-03 0:00 ada routine reading c data problem Mindy Matusewicz
1997-04-05 0:00 ` Jerry van Dijk [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox