Newsgroups: comp.lang.c
Path: utzoo!henry
From: henry@zoo.toronto.edu (Henry Spencer)
Subject: Re: How to pass arbitrary 2-d array argument: done!
Message-ID: <1991Jan7.165253.10260@zoo.toronto.edu>
Organization: U of Toronto Zoology
References: <1991Jan6.044056.23028@noose.ecn.purdue.edu> <1991Jan6.052238.16398@zoo.toronto.edu> <15805.2787625f@levels.sait.edu.au>
Date: Mon, 7 Jan 1991 16:52:53 GMT

In article <15805.2787625f@levels.sait.edu.au> marwk@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@zoo.toronto.edu   utzoo!henry
