From: "Jeffrey R. Carter" <spam.not.jrcarter@acm.not.spam.org>
Subject: Re: How to pass two dimensional arrays to C
Date: Sat, 29 Jul 2006 01:14:16 GMT
Date: 2006-07-29T01:14:16+00:00 [thread overview]
Message-ID: <IDyyg.862875$084.34150@attbi_s22> (raw)
In-Reply-To: <GAwyg.10818$E02.3721@newsb.telia.net>
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
next prev parent reply other threads:[~2006-07-29 1:14 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-28 11:06 How to pass two dimensional arrays to C Jerry
2006-07-28 12:27 ` Jeffrey Creem
2006-07-28 12:27 ` Dmitry A. Kazakov
2006-07-28 16:53 ` Adam Beneschan
2006-07-28 20:15 ` Jeffrey R. Carter
2006-07-28 20:46 ` Jerry
2006-07-28 21:14 ` Jeffrey Creem
2006-07-28 22:54 ` Björn Persson
2006-07-29 1:14 ` Jeffrey R. Carter [this message]
2006-07-29 7:11 ` Simon Wright
2006-07-29 22:12 ` Jeffrey R. Carter
2006-07-30 11:18 ` Simon Wright
2006-07-30 11:20 ` Simon Wright
2006-07-29 4:19 ` REH
2006-07-29 4:28 ` REH
2006-07-29 4:30 ` REH
2006-08-14 6:59 ` Dave Thompson
2006-07-29 5:47 ` REH
2006-08-02 8:20 ` Jerry
2006-08-02 9:03 ` Dmitry A. Kazakov
2006-08-02 10:22 ` Jerry
2006-08-02 18:25 ` Björn Persson
2006-08-05 1:03 ` Jerry
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox