Putting as many parentheses as possible in macros
#define SQR(x) x*x
The preprocessor replaces every occurrence of the form
SQR(a)
by the replacement text
a*a
For example:
w = SQR(x) + 1;
z = SQR(w+1);
becomes
w = x*x + 1;
z = w+1*w+1;
This is 2w+1, not (w+1)2 as intended.
Previous slide
Next slide
Back to first slide
View graphic version