PASSING MULTIDIMENSIONAL ARRAYS
Joseph S. D. Yao
jsdy at hadron.UUCP
Sat Nov 30 10:15:11 AEST 1985
In article <138 at brl-tgr.ARPA> jeff at isi-vaxa.arpa (Jeffery A. Cavallaro) writes:
>I have an application where I want to pass a 2D array to a subroutine.
>The data does not easily avail itself to being converted to a 1D array
>of structures. How can one access the array in the subroutine???
>Calling routine:
> struct x a[M][N];
> subrout(M, N, a);
>The only way I can see to do it is:
> subrout(m, n, a)
> struct x *a;
>and do the address arithmetic yourself. ...
Yes, you could do it the second way; and unfortunately this is the
only way to implement a routine that has several different sized
matrices being passed to it. However, it seems to me that you are
implying a known fixed matrix size in your application. In that
case, you can call:
struct x a[M][N];
subrout(a)
and just declare
subrout(arg)
struct x arg[M][N];
{ ...
--
Joe Yao hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}
More information about the Comp.lang.c
mailing list