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,fac49e4000395e10 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: How do I pass a pointer from a C function to Ada83? Date: 1999/01/10 Message-ID: #1/1 X-Deja-AN: 430866727 References: <778sp0$50p$1@holly.prod.itd.earthlink.net> Newsgroups: comp.lang.ada X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Date: 1999-01-10T00:00:00+00:00 List-Id: 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 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;