comp.lang.ada
 help / color / mirror / Atom feed
* ada routine reading c data problem
@ 1997-04-03  0:00 Mindy Matusewicz
  1997-04-05  0:00 ` Jerry van Dijk
  0 siblings, 1 reply; 2+ messages in thread
From: Mindy Matusewicz @ 1997-04-03  0:00 UTC (permalink / raw)



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.

Thank you for your help.

Mindy Matusewicz
Mindy_matusewicz@ny.essd.northgrum.com




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: ada routine reading c data problem
  1997-04-03  0:00 ada routine reading c data problem Mindy Matusewicz
@ 1997-04-05  0:00 ` Jerry van Dijk
  0 siblings, 0 replies; 2+ messages in thread
From: Jerry van Dijk @ 1997-04-05  0:00 UTC (permalink / raw)



>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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-04-05  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-04-03  0:00 ada routine reading c data problem Mindy Matusewicz
1997-04-05  0:00 ` Jerry van Dijk

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