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

前端 未结 8 1719
名媛妹妹
名媛妹妹 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:47

    YES you can have an if statement in a macro. You need to format it correctly. Here is an example:

    #define MY_FUNCTION( x )  if( x ) { PRINT("TRUE"); } else { PRINT("FALSE"); } 
    

提交回复
热议问题