-1
#define MUX(a,b) a*b

MUX(10-5,10+5) = 10+5*10-5 = 10+50-5 = 55

I think MUX(10-5,10+5) = (10-5)*(10+5) = 75, but it's wrong.

Why? Can anyone explain?

phuclv
  • 32,499
  • 12
  • 130
  • 417
John
  • 1
  • 2

1 Answers1

1

It's because macro replacement is entirely textual. If you want parentheses for correct arithmetic, they must be in the replacement text.

Jens
  • 65,924
  • 14
  • 115
  • 171