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!i42g2000cwa.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: How to pass two dimensional arrays to C Date: 28 Jul 2006 09:53:53 -0700 Organization: http://groups.google.com Message-ID: <1154105633.391460.171610@i42g2000cwa.googlegroups.com> References: <1154084819.088112.325730@p79g2000cwp.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1154105638 9692 127.0.0.1 (28 Jul 2006 16:53:58 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 28 Jul 2006 16:53:58 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: i42g2000cwa.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:5994 Date: 2006-07-28T09:53:53-07:00 List-Id: 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. 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); z is not a two-dimensional array; it's an array of pointers. Can I guess that you're not all that familiar with C? * means pointer, so an object of type PLFLT* is a pointer to a PLFLT. It's common to use this idiom to pass a one-dimensional array, because the machine would pass the address of the array anyway (i.e. the address of the leftmost element of the array), and you can use pointer arithmetic on the parameters to get the other elements of the array. (In fact, array indexing in C is really just a shorthand for pointer arithmetic.) But one dimension is all you can do with this idiom; using two *'s doesn't give you a two-dimensional array. PLFLT** is a pointer to a pointer to a PLFLT, which means that the pointer you pass as a parameter has to point to a memory location that contains another pointer. So to use this routine, you'll need to construct an array of pointers somewhere (shouldn't be too hard using 'Access, if your 2-D array has aliased components, but don't take my word for this since I haven't tried it using that compiler). Hope this helps, -- Adam