Is it possible to use a if statement inside #define?

前端 未结 8 1720
名媛妹妹
名媛妹妹 2021-02-02 13:34

I\'m trying to make a macro with the following formula: (a^2/(a+b))*b, and I want to make sure that the there will be no dividing by zero.

#define          


        
8条回答
  •  无人共我
    2021-02-02 13:55

    The problem is that an if statement is not an expression, and doesn't return a value. Besides, there is no good reason to use a macro in this case. In fact, it could cause very serious performance problems (depending on what you pass as macro arguments). You should use a function instead.

提交回复
热议问题