Unnecessary Parenthesis

00704a-Liber nevin1 at ihlpf.ATT.COM
Fri Jul 15 01:32:13 AEST 1988


In article <2089 at ssc-vax.UUCP> dmg at ssc-vax.UUCP (David Geary) writes:

>"Unnecessary" parenthesis are something I use all the time in macro
>definitions, also.

Most of the parentheses in macros ARE necessary as you have shown (but are
usually not sufficient as I will show).

>Consider:

>#define Square(x)  x*x

[David shows why this macro should be redefined as
#define	Square(x)	((x)*(x))
]

but consider the case where you try the following:

int	x;
x = 2;
(void)printf("The square of %d + 1 is %d.\n", x, Square(++x));

The Square macro does not work correctly because the argument has side
effects (this is why parentheses are not sufficient in macros).
-- 
 _ __			NEVIN J. LIBER	..!att!ihlpf!nevin1	(312) 510-6194
' )  )				You are in a little twisty maze of
 /  / _ , __o  ____		 email paths, all different.
/  (_</_\/ <__/ / <_	These are solely MY opinions, not AT&T's, blah blah blah



More information about the Comp.lang.c mailing list