prototyping (oh no! not again??)

John E. Davis davis at pacific.mps.ohio-state.edu
Thu Nov 29 06:00:38 AEST 1990


In article <1990Nov28.010539.22412 at druid.uucp> darcy at druid.uucp (D'Arcy J.M. Cain) writes:
   In <DAVIS.90Nov26144044 at pacific.mps.ohio-state.edu> 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 at ohstpy
internet: davis at pacific.mps.ohio-state.edu



More information about the Comp.lang.c mailing list