Sign in to follow this  
gasto

Macros vs inline functions.

Recommended Posts

Aliii    1456


2) Token pasting and stringization operators ##, #. In C you can use those for template-style stuff but you would use actual templates for that in C++. They are sometimes used in C++ for generating class names for unit test frameworks etc.

 

...and for Assert messages.

Share this post


Link to post
Share on other sites
King Mir    2490
Macros are the last resort tool to reduce code duplication. Functions are always preferable when possible, but sometimes they aren't.

For example, if you want a bunch of template specializations for primitive types that are structurally identical, you can use a macro.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this