Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!sri-spam!mordor!lll-tis!ames!hc!hi!kurt From: kurt@hi.UUCP (Kurt Zeilenga) Newsgroups: comp.lang.c Subject: Re: Two dimensional arrays in C (Oops) Message-ID: <10190@hi.UUCP> Date: Thu, 2-Jul-87 13:50:26 EDT Article-I.D.: hi.10190 Posted: Thu Jul 2 13:50:26 1987 Date-Received: Sat, 4-Jul-87 07:41:24 EDT References: <238@hubcap.UUCP> <245@hubcap.UUCP> Reply-To: kurt@hi.UUCP (Kurt Zeilenga) Organization: U. of New Mexico, Albuquerque Lines: 24 He writes: >in article <238@hubcap.UUCP>, beede@hubcap.UUCP (Me) says: >> >> #define matrix_el(array,i,j) (array[y*sizeof(double)+j]) >> >which of course is completely bogus. I'm not sure _where_ that >sizeof(double) popped in, but anyway the correct version is > >#define matrix_el(array,i,j) (array[i*y+j]) , > Actually, (I'm being picky) a better version is: #define matrix_el(array,i,j) array[(i)*y+(j)] You should always use '(' and ')' to surround arguments in macros (and the macro itself if needed) to insure the evaulation order of any expression in the expanding macro. Mike's macro, if used like matrix(array,i+1,j), would return something a bit different then advertised. -- Kurt Zeilenga (zeilenga@hc.dspo.gov) I want my talk.flame! "So long, Mom, I'm off to kill a commie..."