Passing 2-D Arrays of unknown size ?

Patricia Shanahan ps at fps.com
Thu Dec 21 09:51:57 AEST 1989


I have sometimes used a macro to represent an array, especially when mixing
Fortran and C. 

#define Array(i,j) array[(i)*cols+(j)]

   for(i ...)
       for(j ...)
           some_operation(Array(i,j));

With more complicated macros, it is possible to handle non-zero base arrays.

#define Array(i,j) array[((i)-istart)*cols+(j)-jstart]

And of course column-major rather than row-major:

#define Array(i,j) array[((j)-jstart)*rows+(i)-istart]

And strides:

#define Array(i,j) array[((i)-istart)*cols*istride+((j)-jstart)*jstride]


In all cases the reference looks like Array(i,j).
--
	Patricia Shanahan
	ps at fps.com
        uucp : {decvax!ucbvax || ihnp4 || philabs}!ucsd!celerity!ps
	phone: (619) 271-9940



More information about the Comp.lang.c mailing list