Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site dg_rtp.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gamma!epsilon!zeta!sabre!petrus!bellcore!decvax!mcnc!rti-sel!dg_rtp!throopw From: throopw@dg_rtp.UUCP (Wayne Throop) Newsgroups: net.lang.c Subject: Re: dynamic array parameters Message-ID: <57@dg_rtp.UUCP> Date: Thu, 26-Dec-85 13:36:47 EST Article-I.D.: dg_rtp.57 Posted: Thu Dec 26 13:36:47 1985 Date-Received: Sat, 28-Dec-85 01:33:49 EST References: <977@brl-tgr.ARPA> Lines: 27 To reference an element of a variably sized multi-dimensional array, David Tribble recommends > (*(a + i*d1 + j)) /* same as a[i][j] */ along with using macros to simplify, like so: > #define index(a,i,j) (*(a + i*d1 + j)) > index(a, i, j) /* same as a[i][j] */ Good idea. I'd just like to note that, using pointer/array equivalence, the somewhat complicated expression can be written a little less confusingly, as a[i*d1 + j] It might still be advisable to use the macro, but then again, maybe not. The more-than-two-dimensional cases are still pretty confusing: a[(i*d1 + j)*d2 + k] Also, I'd recommend declaring the formal "a" as "int a[]" rather than "int *a", unless it is important for some reason to treat "a" as an lvalue. -- Wayne Throop at Data General, RTP, NC !mcnc!rti-sel!dg_rtp!throopw