How to pass arbitrary 2-d array argument: done!
Henry Spencer
henry at zoo.toronto.edu
Tue Jan 8 03:52:53 AEST 1991
In article <15805.2787625f at levels.sait.edu.au> marwk at levels.sait.edu.au 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.
>>
>The method is quite straight forward and I have done it but I cannot find the
>code at the moment, but I describe its method here.
>
>int size = sizeof(int) * M * N /* number of bytes required /*
>
>int *a; /* a 2-D array */
Uh, this isn't a 2D array at all; it's a pointer to a vector of values, and
you are doing the address arithmetic yourself to simulate an array. That's
quite workable, but it's probably not what the original poster was after.
--
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