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!news3.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsfeed.hanau.net!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> Date: Fri, 28 Jul 2006 14:27:53 +0200 Message-ID: NNTP-Posting-Date: 28 Jul 2006 14:27:57 MEST NNTP-Posting-Host: 62e2115e.newsread4.arcor-online.net X-Trace: DXC=45[7FZ_Z>5J7ej[:C4ig8M:ejgIfPPldDjW\KbG]kaMHea\9g\;7NmEFKS@OMU9nkO[6LHn;2LCVN7enW;^6ZC`DIXm65S@:3>O X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:5989 Date: 2006-07-28T14:27:57+02:00 List-Id: On 28 Jul 2006 04:06:59 -0700, Jerry wrote: > In my project to write a binding for a popular plotter written in C, > I've hit a brick wall and the problem might be associated with passing > two-dimensionaal arrays to C. Well, C does not have arrays (of either dimensionality), so you cannot pass an Ada (true) array to C, as-is. You can pass a pointer to its first element. 2D arrays in C are often emulated by using pointers to pointers. This structure is even more distant from Ada's 2D array. > I'm using GNAT on OS X and Xcode. I can > pass one-dimensional arrays OK. Here are the pertinent parts from an > example where the problem happens: > > The C > > typedef double PLFLT; > typedef int PLINT; > > void c_plmesh(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT > opt); [...] > This appears during the call to plmesh. Any ideas? I'd suggest you to start with the Annex B.3. What you need is probably with Interfaces.C; with Interfaces.C.Pointers; type PLFLT is new Interfaces.C.Double; type PLINT is new Interfaces.C.Int; type PLFLT_Array is array (PLINT range <>) of aliased PLFLT; package PLFLT_Pointers is new Interfaces.C.Pointers ( Index => PLINT, Element => PLFLT, Element_Array => 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; package PLFLT_Pointers_To_Pointers is new Interfaces.C.Pointers ( Index => PLINT, Element => PLFLT_Ptr, Element_Array => PLFLT_Ptr_Array, Default_Terminator => null ); subtype PLFLT_Ptr_Ptr is PLFLT_Pointers_To_Pointers.Pointer; procedure plmesh ( x : PLFLT_Ptr; y : PLFLT_Ptr; z : PLFLT_Ptr_Ptr; nx : PLINT; ny : PLINT; opt : PLINT ); pragma Import(C, plmesh, "c_plmesh"); You might wish to write a wrapper to plmesh to be able to pass PLFLT_Array and PLFLT_Ptr_Array down to it. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de