Newsgroups: comp.lang.c
Path: utzoo!telly!druid!darcy
From: darcy@druid.uucp (D'Arcy J.M. Cain)
Subject: Re: prototyping (oh no! not again??)
Organization: D'Arcy Cain Consulting, West Hill, Ontario
Distribution: comp
Date: Wed, 28 Nov 90 01:05:39 GMT
Message-ID: <1990Nov28.010539.22412@druid.uucp>
References: <DAVIS.90Nov26144044@pacific.mps.ohio-state.edu>

In <DAVIS.90Nov26144044@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@druid)     |
D'Arcy Cain Consulting             |   I support gun control.
West Hill, Ontario, Canada         |   Let's start with the government!
+ 416 281 6094                     |
