comp.lang.ada
 help / color / mirror / Atom feed
* How do I pass a  pointer from a C function to Ada83?
@ 1999-01-09  0:00 boolaz
  1999-01-10  0:00 ` Matthew Heaney
  1999-01-10  0:00 ` David C. Hoos, Sr.
  0 siblings, 2 replies; 4+ messages in thread
From: boolaz @ 1999-01-09  0:00 UTC (permalink / raw)


I am trying to pass an array pointer from a C function to my Ada83 program.
I can't seem to get the pragma interface, access type, and/or system.address
stuff to work.  Any suggestions?

Thanks,
R. Frey







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

* Re: How do I pass a  pointer from a C function to Ada83?
  1999-01-09  0:00 How do I pass a pointer from a C function to Ada83? boolaz
  1999-01-10  0:00 ` Matthew Heaney
@ 1999-01-10  0:00 ` David C. Hoos, Sr.
  1 sibling, 0 replies; 4+ messages in thread
From: David C. Hoos, Sr. @ 1999-01-10  0:00 UTC (permalink / raw)



boolaz wrote in message <778sp0$50p$1@holly.prod.itd.earthlink.net>...
>I am trying to pass an array pointer from a C function to my Ada83 program.
>I can't seem to get the pragma interface, access type, and/or
system.address
>stuff to work.  Any suggestions?
>
You didn't specify which Ada83 compiler you're using, so there are some
details which you need to look up in Appendix F for your compiler.
The original Ada83 Standard did con define means to call Ada subprograms
from other languages, but many compilers did implement the feature.  It may
be that you need to use pragma Export, as pragma interface is for calling
other languages from Ada.

Since in C there aren't really any arrays (only address arithmetic), the
Ada83 type that's appropriate is usually System.Address;
You need, then, some way to let the Ada subprogram know about the array
bounds, and declare an Ada constrained array type which is appropriate.

Since I no longer have an Ada83 compiler on my systems at home, I built a
small example using GNAT, but only using Ada83 features.
Here's a small example for a two-dimensional array:

#include <stdlib.h>
int main (void)
{
  extern void show_matrix (double [ ] [], int rows, int cols);
  double matrix [3][4] =
  {
  {1.0, 2.0, 3.0, 4.0},
  {5.0, 6.0, 7.0, 8.0},
  {9.0, 10.0, 11.0, 12.0}
  };
#define COLS(m) (sizeof (m [0]) / sizeof (* * m))
#define ROWS(m) (sizeof (m) / (COLS (m) * sizeof (* * m)))
  adainit ();
  show_matrix (matrix, ROWS (matrix), COLS (matrix));
  adafinal ();
  return (EXIT_SUCCESS);
}
with Text_IO;
package body Matrices is

   package LFIO is new Text_Io.Float_Io (Long_Float);

   procedure Show_Matrix
   (Matrix_Address : System.Address;
    Rows           : Natural;
    Columns        : Natural)
   is
      type Matrix is array (0 .. Rows - 1, 0 .. Columns - 1) of Long_Float;
      The_Matrix : Matrix;
      for The_Matrix use at Matrix_Address;
   begin
      Text_IO.Put_Line ("Rows:" & integer'image (Rows));
      Text_IO.Put_Line ("Cols:" & integer'image (Columns));
      for R in The_Matrix'Range (1) loop
         for C in The_Matrix'Range (2) loop
            Text_IO.Put
              ("A[" & Integer'Image (R) & " ][" & Integer'Image (C) & " ]
=");
            LFIO.Put (The_Matrix (R, C));
            Text_Io.New_Line;
         end loop;
      end loop;
   end Show_Matrix;

end Matrices;

with System;
package Matrices is
   procedure Show_Matrix
     (Matrix_Address : System.Address;
      Rows           : Natural;
      Columns        : Natural);
   pragma Export (C, Show_Matrix, "show_matrix");
end Matrices;








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

* Re: How do I pass a  pointer from a C function to Ada83?
  1999-01-09  0:00 How do I pass a pointer from a C function to Ada83? boolaz
@ 1999-01-10  0:00 ` Matthew Heaney
  1999-01-10  0:00   ` David C. Hoos, Sr.
  1999-01-10  0:00 ` David C. Hoos, Sr.
  1 sibling, 1 reply; 4+ messages in thread
From: Matthew Heaney @ 1999-01-10  0:00 UTC (permalink / raw)


"boolaz" <boolaz@earthlink.net> writes:

> I am trying to pass an array pointer from a C function to my Ada83 program.
> I can't seem to get the pragma interface, access type, and/or system.address
> stuff to work.  Any suggestions?


You must provide the smallest example that will compile.  We can't help
you without a sample of code.

That being said, here are some ideas.

o  You probably don't need to use System.Address anywhere.  Interface
and Convention pragmas largely obviate the need for typeless interface
programming. 

o  Be careful with an access type that designates an uncontrained array
subtype.  

o  Are you using the types in package Interfaces.C and its children?








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

* Re: How do I pass a  pointer from a C function to Ada83?
  1999-01-10  0:00 ` Matthew Heaney
@ 1999-01-10  0:00   ` David C. Hoos, Sr.
  0 siblings, 0 replies; 4+ messages in thread
From: David C. Hoos, Sr. @ 1999-01-10  0:00 UTC (permalink / raw)



Matthew Heaney wrote in message ...
>"boolaz" <boolaz@earthlink.net> writes:
<snip>
>o  Are you using the types in package Interfaces.C and its children?
>
Interfaces.C in Ada83?








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

end of thread, other threads:[~1999-01-10  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-01-09  0:00 How do I pass a pointer from a C function to Ada83? boolaz
1999-01-10  0:00 ` Matthew Heaney
1999-01-10  0:00   ` David C. Hoos, Sr.
1999-01-10  0:00 ` David C. Hoos, Sr.

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