From: "Jerry" <lanceboyle@qwest.net>
Subject: Re: How to pass two dimensional arrays to C
Date: 2 Aug 2006 03:22:39 -0700
Date: 2006-08-02T03:22:39-07:00 [thread overview]
Message-ID: <1154514159.512901.37810@i3g2000cwc.googlegroups.com> (raw)
In-Reply-To: 11bdwcpsmwfhg$.1idncjntcp3i5.dlg@40tude.net
Dmitry A. Kazakov wrote:
> On 2 Aug 2006 01:20:34 -0700, Jerry wrote:
>
> > =============== my_common.ads
> > package My_Common is
> > type Long_Float_Array_1D is array (Integer range <>) of aliased
> > Long_Float;
> > type Long_Float_Array_2D is array (Integer range <>, integer range
> > <>) of aliased Long_Float;
>
> You cannot be sure that Integer is Interfaces.C.Int and Long_Float is
> Interfaces.C.Double.
My understanding is that with GNAT, these equivalences are guaranteed.
I know that what I've done is bad practice for portability, but I don't
think that it is the source of my problems. Please correct me if I am
wrong. However, I'll double-check this.
>
> > end My_Common;
> >
> > =============== plplotthin.ads
> > with
> > Interfaces.C,
> > Interfaces.C.Pointers,
> > My_Common;
> > use
> > Interfaces.C,
> > Ada.Text_IO;
> >
> > package PLplotThin is
> > subtype PLINT is Integer;
> > subtype PLFLT is Long_Float;
>
> Same as above.
>
> > subtype PL_Float_Array is My_Common.Long_Float_Array_1D;
> > subtype PL_Float_Array_2D is My_Common.Long_Float_Array_2D;
> >
> > package PLFLT_Pointers is new Interfaces.C.Pointers
> > (Index => PLINT,
> > Element => PLFLT,
> > Element_Array => PL_Float_Array, -- was PLFLT_Array
> > Default_Terminator => 0.0);
> > subtype PLFLT_Ptr is PLFLT_Pointers.Pointer;
> > type PLFLT_Ptr_Array is array (PLINT range <>) of aliased
> > PLFLT_Ptr;
> >
> > procedure plmesh(
> > x : PL_Float_Array;
> > y : PL_Float_Array;
> > z : PLFLT_Ptr_Array;
> > nx : PLINT;
> > ny : PLINT;
> > opt : PLINT);
> > pragma Import(C, plmesh, "c_plmesh");
> > end PLplotThin;
> >
> > =============== plplot.adb
> > with
> > PLplotThin,
> > My_Common,
> > Interfaces.C.Pointers,
> > Interfaces.C;
> > use
> > PLplotThin,
> > My_Common,
> > Interfaces.C;
> >
> > package body PLplot is
> >
> > procedure Mesh_3D
> > (x, y : Long_Float_Array_1D;
> > z : in out Long_Float_Array_2D;
> > Options : Integer) is
> >
> > Index_Of_First_Column : Integer := z'First(2);
> >
> > Pointer_Array : PLFLT_Ptr_Array(z'range(1));
> >
> > begin
> > for Index in z'range(1) loop
> > Pointer_Array(Index) := z(Index, Index_Of_First_Column)'access;
>
> Use Unchecked_Access here.
I tried that before and got a segfault.
>
> > end loop;
> > plmesh(x, y, Pointer_Array, x'Length, y'Length, Options);
> > end Mesh_3D;
> > end PLplot;
>
> --
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de
Best,
Jerry
next prev parent reply other threads:[~2006-08-02 10:22 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
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 [this message]
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