comp.lang.ada
 help / color / mirror / Atom feed
From: "Björn Persson" <spam-away@nowhere.nil>
Subject: Re: How to pass two dimensional arrays to C
Date: Fri, 28 Jul 2006 22:54:30 GMT
Date: 2006-07-28T22:54:30+00:00	[thread overview]
Message-ID: <GAwyg.10818$E02.3721@newsb.telia.net> (raw)
In-Reply-To: <1154119563.642347.13670@b28g2000cwb.googlegroups.com>

Jerry wrote:
> I would expect that C would simply expect
> a blob of MN units of memory where each unit is the sizeof(int) and
> rely on M and N being passed as parameters to parse it up correctly.

As C, the language, has no concept of two-dimensional arrays, it can't 
expect anything at all about them. c_plmesh, the function, could have 
been written to expect this, but according to the declaration you posted 
it wasn't.

> The overall thing I have to figure out, I think, is how to convert a
> subtype of Long_Float_Array_2D such as PL_Float_Array_2D into an array
> of pointers.

I think something like this should work:

procedure PLmesh
   (x   : PL_Float_Array;
    y   : PL_Float_Array;
    z   : PL_Float_Array_2D;
    opt : PLINT)
is
    Pointer_Array : PLFLT_Ptr_Array(z'Range(1));
begin
    for Index in z'Range(1) loop
       Pointer_Array(Index) := z(Index, 1)'Access;
    end loop;
    c_plmesh(x, y, Pointer_Array, z'Length(1), z'Length(2), opt);
end PLmesh;

That's just to show the idea. Be sure to check the details carefully, 
especially in what order the elements of z are stored.

-- 
Bj�rn Persson                              PGP key A88682FD
                    omb jor ers @sv ge.
                    r o.b n.p son eri nu



  parent reply	other threads:[~2006-07-28 22:54 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-28 11:06 How to pass two dimensional arrays to C Jerry
2006-07-28 12:27 ` Jeffrey Creem
2006-07-28 12:27 ` Dmitry A. Kazakov
2006-07-28 16:53 ` Adam Beneschan
2006-07-28 20:15 ` Jeffrey R. Carter
2006-07-28 20:46 ` Jerry
2006-07-28 21:14   ` Jeffrey Creem
2006-07-28 22:54   ` Björn Persson [this message]
2006-07-29  1:14     ` Jeffrey R. Carter
2006-07-29  7:11       ` Simon Wright
2006-07-29 22:12         ` Jeffrey R. Carter
2006-07-30 11:18           ` Simon Wright
2006-07-30 11:20           ` Simon Wright
2006-07-29  4:19   ` REH
2006-07-29  4:28     ` REH
2006-07-29  4:30       ` REH
2006-08-14  6:59     ` Dave Thompson
2006-07-29  5:47 ` REH
2006-08-02  8:20 ` Jerry
2006-08-02  9:03   ` Dmitry A. Kazakov
2006-08-02 10:22     ` Jerry
2006-08-02 18:25   ` Björn Persson
2006-08-05  1:03 ` Jerry
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox