Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Beginner
Jan 3, 2002

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)
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap