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!genrad!panda!talcott!harvard!seismo!brl-tgr!gwyn From: gwyn@brl-tgr.ARPA (Doug Gwyn ) Newsgroups: net.lang.c Subject: Re: How to pass subarrays? Message-ID: <10378@brl-tgr.ARPA> Date: Thu, 2-May-85 17:03:24 EDT Article-I.D.: brl-tgr.10378 Posted: Thu May 2 17:03:24 1985 Date-Received: Sat, 4-May-85 00:47:52 EDT References: <2839@ncsu.UUCP> Organization: Ballistic Research Lab Lines: 31 > #define S 20 > main() > { > int big[S][S], > AverageAtCenter; > > GenerateArray( big ); > AverageAtCenter = LocalAverage( &big[ S/2 ][ S/2 ] ); > printf( "Average at center is %d\n", AverageAtCenter ); > } > > LocalAverage( window ) > int window[S][S], > result; > { > result = window[-1][0] + window[0][1] + > window[1][0] + window[0][-1]; > result /= 4; > return result; > } (1) I don't think "result" is declared in the right place. (2) You're passing an (int *) actual argument to the LocalAverage function, but you have declared its formal parameter as an SxS array, which is one level difference of dereferencing. The formal parameter is equivalent to int window[][S]; or int (*window)[S]; Because of the way code is generated, you can actually get away with this type punning in this particular case.