Passing 2-D Arrays of unknown size ?

Ray Wallace wallace at oldtmr.dec.com
Thu Dec 21 07:04:57 AEST 1989


In article <3180 at uceng.UC.EDU>, mfinegan at uceng.UC.EDU (michael k finegan)
writes... 
>    Is there a method for passing/using multi-D arrays in subroutines,
>without specifying the column (fastest changing) dimension in advance ? No way

Your solution_func3() is what I would use with a slight modification to
illiminate the calculation drawback you mention...

solution_func3(array,rows,cols)
char *array;
int rows, cols;
{
    int i,j;

    for(i=0, i<rows, ++i)
        for(j=0, j<cols, ++j )
            some_operation(*array++);
  /*
   * Of course if you want to do some kind of random indexing then you still
   * end up with doing the calculation you stated "[i*cols + j]".
   */
}
---
Ray Wallace		
		(INTERNET,UUCP) wallace at oldtmr.enet.dec.com
		(UUCP)		...!decwrl!oldtmr.enet!wallace
		(INTERNET)	wallace%oldtmr.enet at decwrl.dec.com
---



More information about the Comp.lang.c mailing list