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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!news.karotte.org!news2.arglkargh.de!noris.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: How to pass two dimensional arrays to C Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1154084819.088112.325730@p79g2000cwp.googlegroups.com> <1154506834.761313.94330@m79g2000cwm.googlegroups.com> Date: Wed, 2 Aug 2006 11:03:46 +0200 Message-ID: <11bdwcpsmwfhg$.1idncjntcp3i5.dlg@40tude.net> NNTP-Posting-Date: 02 Aug 2006 11:03:46 MEST NNTP-Posting-Host: 83aa1aa5.newsread2.arcor-online.net X-Trace: DXC=0HnQLj:9l^\>K]\3>m]<[UQ5U85hF6f;TjW\KbG]kaMXAV6U:Z=fE=_m>=XUOjY_LV[6LHn;2LCV^7enW;^6ZC`TIXm65S@:3>_ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:6060 Date: 2006-08-02T11:03:46+02:00 List-Id: 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. > 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. > 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