Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ncsu.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!mcnc!ncsu!glb From: glb@ncsu.UUCP (Griff Bilbro) Newsgroups: net.lang.c Subject: How to pass subarrays? Message-ID: <2839@ncsu.UUCP> Date: Wed, 1-May-85 14:43:05 EDT Article-I.D.: ncsu.2839 Posted: Wed May 1 14:43:05 1985 Date-Received: Fri, 3-May-85 04:44:37 EDT Organization: N.C. State University, Raleigh Lines: 35 << Propitiation for the line eating trolls >> I'm doing a lot of 2D programming lately. Conceptually everything behaves like 2D arrays, so I want to access things with 2 indices. That's easy enough, but I want to pass a window of an array to a sub- routine so that it looks like the original array except that it's offset. I want the subroutine to be able to use negative subscripts. Here's an illustration: #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; } At this point, I don't care about speed. I need the code to look like the math. The code above works, but lint complains. Why does lint complain? How can I make C do the indexing arithmetic the way I want that lint likes? It amounts to saying w[i][j] is equivalent to w[i*S+j]. Can't I declare a argument pointer to index like this?