prototyping (oh no! not again??)

Michael Salmon epames at eos.ericsson.se
Thu Nov 29 02:05:10 AEST 1990


In article <DAVIS.90Nov26144044 at pacific.mps.ohio-state.edu> John E. Davis writes:
>   double trace(double **matrix, int dim)
                        ^^ this is pointer to pointer to double
>   {
>      int i;
>      double t;
>
>      t = 0.0;
>      i = 0;
>      while(i++ < dim) t = t + matrix[i][i];
                                ^^ this is *(*(matrix + i) + i)
>      return t;
>   }
I don't think your compiler should have allowed this as you were
passing a pointer to a double not a pointer to a pointer to a double.
What has happened is that the double at matrix[0][i] is treated as a
pointer and dereferenced with an offset of i, not surprisingly you
got an error.

Michael Salmon
L.M.Ericsson
Stockholm



More information about the Comp.lang.c mailing list