Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site h.cs.cmu.edu Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!whuxl!whuxlm!akgua!gatech!seismo!rochester!pt.cs.cmu.edu!h.cs.cmu.edu!rfb From: rfb@h.cs.cmu.edu (Rick Busdiecker) Newsgroups: net.sources Subject: Retraction (matrix routine) Message-ID: <267@h.cs.cmu.edu> Date: Mon, 18-Nov-85 09:39:14 EST Article-I.D.: h.267 Posted: Mon Nov 18 09:39:14 1985 Date-Received: Wed, 20-Nov-85 21:03:38 EST Organization: Carnegie-Mellon University, CS/RI Lines: 64 In a previous post I said that the declarations: double matrix [m][n] and double (matrix [m])[n] were not equivalent. Duane Williams pointed out and cc convinced me that I was wrong. In order to treat a two dimensional array as **matrix you need to set the pointers up yourself. The routine make_mat() in the following program works (I tested it this time!). This type of matrix is slightly more versatile than the one you get with a standard declaration because it contains the standard representation which you can refer to as (test+m) when passing it to a function which takes standard matrices. #define HEIGHT 2 #define WIDTH 3 char *valloc (); double **make_mat (m, n) { double **result; int i; result = (double **)valloc (m * (n + 1)); for (i = 0; i < m; i++) *(result + i) = (double *)result + m + i * n; return (result); } main () { double **test; int i, j; test = make_mat (HEIGHT, WIDTH); for (i = 0; i < HEIGHT; i++) for (j = 0; j < WIDTH; j++) { test [i][j] = i * WIDTH + j; printf ("test [%d][%d] = %g\t%d\n", i, j, test [i][j], (&(test [i][j]) - &(test [0][0]))); } putchar ('\n'); for (i = 0; i < HEIGHT; i++) for (j = 0; j < WIDTH; j++) printf ("test [%d][%d] = %g\n", i, j, test [i][j]); } Sorry for any confusion I caused people. --------------------------------------------------------------------------- Rick Busdiecker ARPA: rfb@h.cs.cmu.edu Carnegie-Mellon University UUCP: ...!seismo!h.cs.cmu.edu!rfb Mathematics Department AT&T: (412) 521-1459 USPS: 4145 Murray Ave. 15217 ---------------------------------------------------------------------------