Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!gatech!hubcap!beede From: beede@hubcap.UUCP (Mike Beede) Newsgroups: comp.lang.c Subject: Re: Two dimensional arrays in C Message-ID: <238@hubcap.UUCP> Date: Mon, 29-Jun-87 19:10:46 EDT Article-I.D.: hubcap.238 Posted: Mon Jun 29 19:10:46 1987 Date-Received: Wed, 1-Jul-87 01:59:15 EDT References: <2215@mmintl.UUCP> Organization: Clemson University, Clemson, SC Lines: 33 in article <2215@mmintl.UUCP>, franka@mmintl.UUCP (Frank Adams) says: ] ] In article <733@cod.UUCP> murphys@cod.UUCP (Steven P. Murphy) writes: ]>The following example is what I would like to be able to do. Is it possible ? ]>... ]>matrix_stuff(a, b, array, x, y); ]> ]>int a, b, x, y; ]>double array[x][y]; ] ] No. Array bounds in C have to be constants. To do this, you would have to ] do the array arithmetic explicitly. Sorry. However, you CAN do the arithmetic explicitly if you like, using macros to maintain fair readability: something like #define matrix_el(array,i,j) (array[y*sizeof(double)+j]) which produces an l-valued expression. At the same time, you can insert temporary bounds-checking until you're sure your code is correct (or forever, whichever is smaller :-) ). Now, of course, your declaration for array is double array[]; and you can have things like matrix_el(A,i,j) = matrix_el(A,i+1,j) , etc. Of course, since this depends on the value of y, it is still sloppy, but you can include y as a discriptor bolted onto the array or something similar, if you like (which the macro would reference). -- Mike Beede UUCP: . . . !gatech!hubcap!beede Computer Science Dept. ARPA: BEEDE@TECNET-CLEMSON.ARPA Clemson University INET: beede@hubcap.clemson.edu Clemson SC 29631-1906 PH: (803)656-{2845,3444}