What problems might the following macro bring to the application?

前端 未结 6 2124
伪装坚强ぢ
伪装坚强ぢ 2021-01-27 02:50

Can the following macro bring problems?

#define sq(x) x*x

If yes, then how and why?please help.

6条回答
  •  梦谈多话
    2021-01-27 03:10

    For one, operator precedence would be messed up:

    sq(2+2); // author wants 4*4, but gets 2+2*2+2. 
    

提交回复
热议问题