devxlogo

Parenthesize Macro Arguments

Parenthesize Macro Arguments

It’s a good idea to parenthesize every macro argument. For example:

 #define MAX(x,y)  (x)>(y)?(x):(y)

The parentheses ensure that the macro is evaluated correctly, even if the user passes complex expressions that contain operators as arguments:

 int a=0,n=1,b=0,c=0;int q=MAX(a+8-n, b==c?b:c)

devx-admin

Share the Post: