How to pass arbitrary 2-d array argument ?

Henry Spencer henry at zoo.toronto.edu
Sun Jan 6 16:22:38 AEST 1991


In article <1991Jan6.044056.23028 at noose.ecn.purdue.edu> luj at delta.ecn.purdue.edu (Jun Lu) writes:
>It would be nice if I can have a "subroutine" which takes arbitrary matrices as
>arguments and performs some operations on them. The dimensions of the 2-d
>array are not known a priori...

Can't be done in C.  The dimensions of an array, with the exception of the
first, must be known at compile time.

(Well, "can't be done" is an exaggeration, but what you end up doing is
cheating, declaring the arguments as pointers and doing the subscript
arithmetic yourself rather than using [] notation.)

This is generally considered a deficiency, but it is harder to solve than
it looks.  Some compilers have extensions to do it, although most of those
extensions have problems of one kind or another.  There is work being done
on finding a good solution.
-- 
If the Space Shuttle was the answer,   | Henry Spencer at U of Toronto Zoology
what was the question?                 |  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.lang.c mailing list