Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!bloom-beacon!eru!luth!sunic!mcsun!unido!mikros!mwtech!martin From: martin@mwtech.UUCP (Martin Weitzel) Newsgroups: comp.lang.c Subject: Re: Passing 2-D Arrays of unknown size ? Message-ID: <566@mwtech.UUCP> Date: 20 Dec 89 20:28:22 GMT References: <3180@uceng.UC.EDU> Reply-To: martin@mwtech.UUCP (Martin Weitzel) Organization: MIKROS Systemware, Darmstadt/W-Germany Lines: 34 In article <3180@uceng.UC.EDU> mfinegan@uceng.UC.EDU (michael k finegan) writes: [some lines deleted] - Is there a method for passing/using multi-D arrays in subroutines, [most of examples deleted] -solution_func3(array,rows,cols) -char *array; -int rows, cols; -{ - int i,j; - - /* But now I can't use array[][] notation, - * and must calculate the indices myself ! - */ - for(i ...) - for(j ...) - some_operation(array[i*cols + j]); ^^^^^^^^^ Exactly this is, what a compiler would have to - and can not do at compile time, because cols is only know at runtime. You cannot have the array[][] notatation, but you could write a preprocessor makro: #define ARR(x,y) (array[(x)*cols+(y)]) to make the following a (little) more readable: - - /* with typically: array[(long calculated value)*stride*cols + - * stride*(another calculated value)] - */ ARR((long calculated value)*stride, stride*(another calculated value)). Of course, you could consider a switch to C++, where you could overload the []-Operator ... -- Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83