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)
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist