This one bit me today

Brian Matthews 6sigma at polari.UUCP
Sat Oct 7 07:32:38 AEST 1989


In article <832 at crdos1.crd.ge.COM> davidsen at crdos1.UUCP (bill davidsen) writes:
|In article <2432 at hub.UUCP>, dougp at voodoo.ucsb.edu writes:
||    int a=1,b=2,*p=&a,c;
||    c=b/*p;
||  First real flaw in the C grammer [sic] I have found.
|  It pops up in macros from time to time. Consider:
|	#define xavg(m) (sum+3)/m

That's why anyone who knows what they're doing will parenthesize each
argument in the expansion of the macro and use liberal whitespace, thusly:

#define xavg(m)	(sum + 3) / (m)

Then things like xavg (*p) and xavg (x + y) work as expected.
-- 
Brian L. Matthews	blm at 6sigma.UUCP



More information about the Comp.lang.c mailing list