-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
  • 37,963
  • 15
  • 156
  • 475
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
  • 69,818
  • 15
  • 125
  • 179