Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!noose.ecn.purdue.edu!news From: luj@delta.ecn.purdue.edu (Jun Lu) Newsgroups: comp.lang.c Subject: How to pass arbitrary 2-d array argument ? Message-ID: <1991Jan6.044056.23028@noose.ecn.purdue.edu> Date: 6 Jan 91 04:40:56 GMT Sender: news@noose.ecn.purdue.edu (USENET news) Followup-To: comp.lang.c Organization: Purdue University School of Aeronautics and Astronautics Lines: 45 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@ecn.purdue.edu -- -- Aeronautics & Astronautics Bitnet: luj%ecn.purdue.edu@purccvm -- -- Purdue University UUCP: pur-ee!luj -- -- W. Lafayette, IN 47907 Phone:317-494-9410 Fax:317-494-0307 --