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!postnews.google.com!m79g2000cwm.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 01:20:34 -0700 Organization: http://groups.google.com Message-ID: <1154506834.761313.94330@m79g2000cwm.googlegroups.com> References: <1154084819.088112.325730@p79g2000cwp.googlegroups.com> NNTP-Posting-Host: 71.35.35.3 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1154506838 9557 127.0.0.1 (2 Aug 2006 08:20:38 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 2 Aug 2006 08:20:38 +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: m79g2000cwm.googlegroups.com; posting-host=71.35.35.3; posting-account=Ax24hA0AAABV39UFqUVhb0kauOuAbI3T Xref: g2news2.google.com comp.lang.ada:6059 Date: 2006-08-02T01:20:34-07:00 List-Id: I have attempted to implement the approach suggested by Dmitry and Bj=F6rn. With apologies for a posting a fair bit of code, here is an abbreviated version of what I currently have, with file names (GNAT) indicated by =3D=3D=3D=3D=3D. I hope I haven't edited out something relevan= t=2E =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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; end My_Common; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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; 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 =3D> PLINT, Element =3D> PLFLT, Element_Array =3D> PL_Float_Array, -- was PLFLT_Array Default_Terminator =3D> 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; =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 :=3D z'First(2); -- package PLFLT_Pointers is new Interfaces.C.Pointers -- (Index =3D> PLINT, -- Element =3D> PLFLT, -- Element_Array =3D> PL_Float_Array, -- was PLFLT_Array -- Default_Terminator =3D> 0.0); -- -- subtype PLFLT_Ptr is PLFLT_Pointers.Pointer; -- type PLFLT_Ptr_Array is array (PLINT range <>) of aliased PLFLT_Ptr; Pointer_Array : PLFLT_Ptr_Array(z'range(1)); begin for Index in z'range(1) loop Pointer_Array(Index) :=3D z(Index, Index_Of_First_Column)'access; end loop; plmesh(x, y, Pointer_Array, x'Length, y'Length, Options); end Mesh_3D; end PLplot; This generates one compile-time error, "plplot.adb:990:37: non-local pointer cannot point to local object." With a rather lucky google hit, I was led to Cohen's book, 2nd edition, page 356, where he states the "Acces-Type Lifetime Rule: An attribute X'Access yielding a result belonging to an access type T is only allowed if X can remain in existence at least as long as T." That kinda made sense to me, so I moved the declaration of the package PLFLT_Pointers is new Interfaces.C.Pointers along with its two associated subtype and type declarations inside the scope of procedure Mesh_3D, where you can see it commented-out above. With this uncommented and the similar declarations in plplotthin.ads commented-out, I get the compile error "plplotthin.ads:1025:56: "PLFLT_Ptr_Array" is undefined." Duh. So how do I fix this conundrum? Jerry