How to pass arbitrary 2-d array argument ?
Jun Lu
luj at delta.ecn.purdue.edu
Sun Jan 6 15:40:56 AEST 1991
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. In other words, how do you add two
matrices together portably in C ? ( see following scenario descriptions )
main()
{
double m1[4][2], m2[4][2], m[4][2];
double a[5][5], b[5][5], c[5][5];
/* init m1, m2 ... */
madd(m1, m2, m, 4, 2);
madd(a, b, c, 5, 5);
/* ... */
}
madd(a, b, c, m, n)
/* args --- how ???(Note n is not known at compile time, but we assume that
the type of the 2-d array elements are known, i.e. double */
{
/*
* some work --- how ????
*/
for (i = 0; i < m; i++) /* fucntionality of madd() */
for (j = 0; j < n; j++)
c[i][j] = a[i][j] + b[i][j];
}
No calling Fortran from C please.
Any suggestions/comments/pointers are welcome. I'm looking forward to
hearing from you ...
Thanks,
--
-- Jun Lu Internet:luj at ecn.purdue.edu --
-- Aeronautics & Astronautics Bitnet: luj%ecn.purdue.edu at purccvm --
-- Purdue University UUCP: pur-ee!luj --
-- W. Lafayette, IN 47907 Phone:317-494-9410 Fax:317-494-0307 --
More information about the Comp.lang.c
mailing list