Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!brl-tgr!gwyn From: gwyn@brl-tgr.ARPA (Doug Gwyn ) Newsgroups: net.lang.c Subject: Re: C array follies 1 Message-ID: <1302@brl-tgr.ARPA> Date: Sat, 7-Sep-85 02:37:05 EDT Article-I.D.: brl-tgr.1302 Posted: Sat Sep 7 02:37:05 1985 Date-Received: Mon, 9-Sep-85 01:04:04 EDT References: <171@rtp47.UUCP> Organization: Ballistic Research Lab Lines: 30 > void f(x) > int x[2][2][2]; > { > ... > } > void main(){ > int x[2][2][2]; > ... > f(x); > } > ... > I think that most systems will print "4 16 8" (or equivalent) ... Yes, you are not actually passing an entire array to the function f() but rather just a pointer to a 2x2 array of ints. C lets you misdeclare this void f( int x[2][2][2] ); /* ANSI C assumed */ which is the real misfeature. The "correct" declaration is technically void f( int (*x)[2][2] ); which also is supported by C (thankfully), or if you prefer, void f( int x[][2][2] ); Fortunately, old C did not have this misfeature for structs/unions, so it was possible to add to C the ability to pass struct arguments in addition to just pointers to them. For reasons of backward compatibility, it is unfortunately NOT possible to change C so that f( x ); actually passes the array and not just a pointer to the first element. Maybe language "D" can fix all C's mistakes (ha). Meanwhile we just have to learn to cope with them.