Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!usc!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!davis From: davis@pacific.mps.ohio-state.edu ("John E. Davis") Newsgroups: comp.lang.c Subject: Re: prototyping (oh no! not again??) Message-ID: Date: 28 Nov 90 19:00:38 GMT References: <1990Nov28.010539.22412@druid.uucp> Sender: news@pacific.mps.ohio-state.edu Reply-To: davis@pacific.mps.ohio-state.edu (John E. Davis) Distribution: comp Organization: "Dept. of Physics, The Ohio State University" Lines: 48 In-reply-to: darcy@druid.uucp's message of 28 Nov 90 01:05:39 GMT In article <1990Nov28.010539.22412@druid.uucp> darcy@druid.uucp (D'Arcy J.M. Cain) writes: In John E. Davis writes: > double trace(double **matrix, int dim) > { > int i; > double t; > > t = 0.0; > i = 0; > while(i++ < dim) t = t + matrix[i][i]; My first reaction was that you wind up accessing matrix[10][10] so you are accessing an area outside of the array. you should use: for (i = 0; i < dim; i++) ... but that doesn't explain why it works when you use: > double trace(double matrix[10][10],int n) unless that changes the program just enough that the area following the array is now part of your data space. If so that is just bad news somewhere else anyway. Try using the for construct. This is not the function that I really had in mind. I 'invented' this one as I was composing the article as a quick example the make my point. I guess I should write: i = 0; while(i < dim) t = t + matrix[i][i++]; I noticed this after I posted it. By the way, I have been following the C vs Fortran thread. It seems that not enough computer science types understand the needs of a scientist. For example, it is not at all uncommon to have *big* multidimensional arrays, eg., arrays with 5 or more subscripts. As somone pointed out, we do not randomly access the elements. Most of the time only one subscript is varying so the advantages of pointers to pointers to pointers to ... to double is unclear. Also, what C lacks is something as the fortran ** operator. Why can't this be implemented as a binary operator say as x^y. As far as I understand it, the ** operator is smart enough to to convert f(x) ** 2 to (y = f(x), y*y) or something like this; however I am not sure what the pow function does. Does it do: pow(x,2) = exp(2*log(x)) or some faster equivilent? Perhaps someone can fill me in. -- John bitnet: davis@ohstpy internet: davis@pacific.mps.ohio-state.edu