Passing Multidimensional Arrays

Ken Turkowski ken at turtlevax.UUCP
Mon Dec 9 13:30:52 AEST 1985


In article <365 at codas.UUCP> mikel at codas.UUCP (Mikel Manitius) 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???
>
>How about this:
>#define		X	100
>#define		Y	100
>struct	x a[Y][X];
>subrout(i, j, a)
>int	i; int	j; struct x *a[];
>{
>	...a[j][i]...
>}
>And use i and j as boundary limits.

Unfortunately, this simplistic approach doesn't work because the offset
of a[3][4] from &a[0][0] is not the same when a is declared as a[5][5]
versus a[50][50].
-- 
Ken Turkowski @ CIMLINC, Menlo Park, CA
UUCP: {amd,decwrl,hplabs,seismo,spar}!turtlevax!ken
ARPA: turtlevax!ken at DECWRL.DEC.COM



More information about the Comp.lang.c mailing list