prototyping (oh no! not again??)

D'Arcy J.M. Cain darcy at druid.uucp
Wed Nov 28 12:05:39 AEST 1990


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.

-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   I support gun control.
West Hill, Ontario, Canada         |   Let's start with the government!
+ 416 281 6094                     |



More information about the Comp.lang.c mailing list