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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,545a1e8bab85387a X-Google-Attributes: gid103376,public From: jerry@jvdsys.nextjk.stuyts.nl (Jerry van Dijk) Subject: Re: ada routine reading c data problem Date: 1997/04/05 Message-ID: <860206044.12snx@jvdsys.nextjk.stuyts.nl>#1/1 X-Deja-AN: 230757472 Distribution: world References: <33441A45.454D@ny.essd.northgrum.com> Organization: *JerryWare HQ*, Haarlem, Holland Newsgroups: comp.lang.ada Date: 1997-04-05T00:00:00+00:00 List-Id: >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 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