1

I was reading Effective C++: 55 ... and in Item no 2 .. there was this one line of code which I didn't understand

#define CALL_WITH_MAX(a, b) f((a) > (b) ? (a) : (b))

why do we need to parenthesize the arguments in the function called by define (here f() ) ?

X caliber
  • 52
  • 4
  • 1
    macros are "dumb" lexical substitutions. They can easily end up creating syntactic constructs you didn't intend. Parenthesis make that not happen. – xaxxon Dec 20 '20 at 01:43
  • 3
    In particular they don't evaluate operands before substituting them into the expression, so you can get nasty operator precedence issues. This is can be seen with something like `#define SQUARED(x) x * x` because than `SQUARED(1 + 3)` is `1 + 3 * 1 + 3 == 7` instead of `16`. – Nathan Pierson Dec 20 '20 at 01:54

0 Answers0