Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!husc6!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Two dimensional arrays in C Message-ID: <6012@brl-smoke.ARPA> Date: Tue, 23-Jun-87 13:49:25 EDT Article-I.D.: brl-smok.6012 Posted: Tue Jun 23 13:49:25 1987 Date-Received: Fri, 26-Jun-87 05:46:51 EDT References: <733@cod.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 28 In article <733@cod.UUCP> murphys@cod.UUCP (Steven P. Murphy) writes: >matrix_stuff(a, b, array, x, y); >int a, b, x, y; >double array[x][y]; >{ Sorry, that is not legal in C, although the analogous operation is commonly encountered in Fortran programming. In C, formal array parameters must be declared with constant dimensions*, although the leftmost dimension is unimportant (so that [1] or [] will do for it). Keep in mind that an attempt to pass the name of an array as an actual parameter in a function call results in a pointer to the first element of the array as the real parameter. Also remember that all arrays are really 1-dimensional aggregates of objects, which in turn may be arrays. This subject should be covered in any good C programming text, although probably someone like Torek will post examples. The point I wish to make is that you can get into trouble if you try to take an "intuitive" approach to using arrays in C; you need to carefully examine just what the rules are. Once you do that, you'll find several alternate ways to accomplish what you're trying to do. *I once suggested to Dennis Ritchie that this restriction on formal array parameters could be removed, and although he seemed to agree that there was no theoretical problem doing so, we agreed that it would add complexity to compilers. He seemed to think that the feature would be of insufficient general utility to offset the added complexity. (I hope I haven't misrepresented his position; it was a long time ago.)