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
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Aug 28, 1998

Better Alternatives to Macros

Macros in C++ are better avoided. They are unsafe, hard to debug, and may bloat your .exe files. C++ offers significantly better alternatives to them:

1. Function-like macros should be replaced with inline functions. Inline functions are safer since they allow type checking. Furthermore, they also support overloading and can be stepped into during debugging.

2. Constant-like macros should be replaced with const variables or enum types, both of which allow safe type checking and are easier to debug.

In other words, macros in C++ should be confined to conditional compilation solely.

Danny Kalev
 
Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date