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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6b3a3c920575b35a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns13feed!worldnet.att.net!attbi_s22.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How to pass two dimensional arrays to C References: <1154084819.088112.325730@p79g2000cwp.googlegroups.com> <1154119563.642347.13670@b28g2000cwb.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: NNTP-Posting-Host: 12.201.97.176 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s22 1154135656 12.201.97.176 (Sat, 29 Jul 2006 01:14:16 GMT) NNTP-Posting-Date: Sat, 29 Jul 2006 01:14:16 GMT Date: Sat, 29 Jul 2006 01:14:16 GMT Xref: g2news2.google.com comp.lang.ada:6005 Date: 2006-07-29T01:14:16+00:00 List-Id: Bj�rn Persson wrote: > > I think something like this should work: > > procedure PLmesh > (x : PL_Float_Array; > y : PL_Float_Array; > z : PL_Float_Array_2D; > opt : PLINT) > is > Pointer_Array : PLFLT_Ptr_Array(z'Range(1)); > begin > for Index in z'Range(1) loop > Pointer_Array(Index) := z(Index, 1)'Access; > end loop; > c_plmesh(x, y, Pointer_Array, z'Length(1), z'Length(2), opt); > end PLmesh; No, you need to create a collection of C-compatible 1D arrays, put the rows of Z into them, and store C-compatible pointers to them in the C-compatible 1D array of pointers. More like type Z_Length is new PL_Float_Array (Z_Range (2) ); pragma Convention (C, Z_Length); type Ptr is access Z_Length; pragma Convention (C, Ptr); type Ptr_List is array (Z'range (1) ) of Ptr; pragma Convention (C, Ptr_List); A : Ptr_List; begin All_Rows : for Row in Z'range (1) loop A (Row) := new Z_Length; All_Columns : for Column in Z'range (2) loop A (Row) (Column) := Z (Row, Column); end loop All_Columns; end loop All_Rows; C_Plmesh (...); -- Reclaim storage? Should be reclaimed automatically since -- Ptr goes out of scope end; -- Jeff Carter "Don't knock masturbation. It's sex with someone I love." Annie Hall 45