prototyping (oh no! not again??)

Henry Spencer henry at zoo.toronto.edu
Wed Nov 28 03:37:16 AEST 1990


In article <DAVIS.90Nov26144044 at pacific.mps.ohio-state.edu> davis at pacific.mps.ohio-state.edu  (John E. Davis) writes:
>   I have a function that takes a 2-d array of unknown dimension and does
>   things with it.  How do I declare and call it?

You can't do this in C.  Period.  Indexing into the array requires knowing
the size of the rows in the array.  C insists on knowing this at compile time,
so the second dimension must be declared as a specific number.  The only way
out of this is to pass a pointer to the array as if it were one-dimensional,
and do the indexing arithmetic yourself.

>   I tried this:
>   double trace(double **matrix, int dim)

Sigh.  Please see any good C textbook for the differences between pointers
and arrays.  This is wrong no matter what shape your array has.
-- 
"I'm not sure it's possible            | Henry Spencer at U of Toronto Zoology
to explain how X works."               |  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.lang.c mailing list