Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!usenet.ins.cwru.edu!abvax!iccgcc!browns From: browns@iccgcc.decnet.ab.com (Stan Brown) Newsgroups: comp.lang.c Subject: Re: prototyping (oh no! not again??) Message-ID: <2152.2752513c@iccgcc.decnet.ab.com> Date: 27 Nov 90 16:42:52 GMT References: Distribution: comp Lines: 63 X-NEWS: iccgcc comp.lang.c: 5098 Path: iccgcc!browns From: browns@iccgcc.decnet.ab.com (Stan Brown) Newsgroups: comp.lang.c Subject: Re: prototyping (oh no! not again??) Message-ID: <2149.275250b3@iccgcc.decnet.ab.com> Date: 27 Nov 90 11:40:35 EST References: Distribution: comp Lines: 48 In article , davis@pacific.mps.ohio-state.edu ("John E. Davis") writes: > I have a function that takes a 2-d array of unknown dimension and does > things with it. How do I declare and call it? > The function was defined thusly: > > double trace(double **matrix, int dim) > { /* stuff deleted */ > } So you have a function that expects a pointer to a pointer to double. Because of the PARTIAL equivalence of arrays and pointers in the specific context of function definitions, you could also say that the function expects an array of pointers to double. Note that neither of these is the same as an array of double--not a one-dimensional or a two-dimensional array of double. The function was called thusly: > > int main() > { > double m[10][10],t; > . > . > t = trace(m,10); > . > . > } > > This dumps core because of segmentation fault. m is a 2-D array of double. This is not compatible with the definition of the function above. BTW, which compiler are you using? It should have rejected the function call if the prototype was in scope. Catching stuff like this before it core dumps is the reason we have prototypes. The cure? Depends on what you're trying to accomplish. With these hints, you might try reading the Frequently Asked Questions again. Pointers and arrays are not the same thing. There are certain cases where a first-level pointer and the name of a 1-D array are treated as the same thing, but I can't think of any way that a second-level pointer and a 2-D array could conform. Please do not attribute these remarks to any other person or company. email: browns@iccgcc.decnet.ab.com Stan Brown, Oak Road Systems, Cleveland, Ohio, USA +1 216 371 0043