Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!zaphod.mps.ohio-state.edu!mips!excelan!crdgw1!crdos1!davidsen From: davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) Newsgroups: comp.lang.c Subject: Re: Passing 2-D Arrays of unknown size ? Message-ID: <1941@crdos1.crd.ge.COM> Date: 20 Dec 89 20:27:37 GMT References: <3180@uceng.UC.EDU> Organization: GE Corp R&D Center, Schenectady NY Lines: 37 Reply-exos:@crdgw1:To: davidsen@crdos1.crd.ge.com (bill davidsen) I don't know of any elegant way, there's a truly ugly way which takes some of the curse off using an array like that in terms of access overhead and ugly code. There is a certain overhead at the start of the execution, so there are tradeoffs. /* I typed this by hand - beware! */ access(array, n, m) int array[]; int n,m; { int **fake; /* will act like array[n][m] */ int work; fake = (int *)malloc(m * sizeof(int)); /* test status here */ fake[0] = array; for (work = 1; work < n; work++) { fake[n] = fake[n-1] + m; } /* now using fake[x][y] gives the same address as array[x][y], if the values of n and m were declared */ /* and don't forget to: */ free(fake); } As I say this is not pretty or clever, but it does tend to make the code a bit more readable. You can also define a macro to do the multiply, but that can add a lot of overhead. -- bill davidsen (davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen) "The world is filled with fools. They blindly follow their so-called 'reason' in the face of the church and common sense. Any fool can see that the world is flat!" - anon