a style question
Dan Bernstein
brnstnd at kramden.acf.nyu.edu
Wed Oct 24 06:51:55 AEST 1990
In article <1990Oct23.160116.10299 at athena.mit.edu> tada at athena.mit.edu (Michael J Zehr) writes:
> v = (a[i-1][j-1] + a[i][j-1] + a[i-1][j+i] +
> a[i-1][j] + a[i][j] + a[i-1][j+1] +
> a[i-1][j+1] + a[i][j-1] + a[i-1][j+1])/9;
At a minimum I'd format this as
v = (a[i-1][j-1] + a[i][j-1] + a[i-1][j+i] +
a[i-1][j ] + a[i][j ] + a[i-1][j+1] +
a[i-1][j+1] + a[i][j-1] + a[i-1][j+1])/9
which makes the j + i pretty obvious. Or a macro:
#define A(b,c) a[i+(b)][j+(c)]
v = ( A(-1,-1) + A(0,-1) + A(-1,+i) +
A(-1, 0) + A(0, 0) + A(-1,+1) +
A(-1,+1) + A(0,-1) + A(-1,+1) ) / 9
#undef A
---Dan
More information about the Comp.lang.c
mailing list