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-7-bit Path: g2news2.google.com!postnews.google.com!i3g2000cwc.googlegroups.com!not-for-mail From: "Jerry" Newsgroups: comp.lang.ada Subject: Re: How to pass two dimensional arrays to C Date: 2 Aug 2006 03:22:39 -0700 Organization: http://groups.google.com Message-ID: <1154514159.512901.37810@i3g2000cwc.googlegroups.com> References: <1154084819.088112.325730@p79g2000cwp.googlegroups.com> <1154506834.761313.94330@m79g2000cwm.googlegroups.com> <11bdwcpsmwfhg$.1idncjntcp3i5.dlg@40tude.net> NNTP-Posting-Host: 71.35.35.3 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1154514163 22279 127.0.0.1 (2 Aug 2006 10:22:43 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 2 Aug 2006 10:22:43 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: i3g2000cwc.googlegroups.com; posting-host=71.35.35.3; posting-account=Ax24hA0AAABV39UFqUVhb0kauOuAbI3T Xref: g2news2.google.com comp.lang.ada:6063 Date: 2006-08-02T03:22:39-07:00 List-Id: 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