dcsimg
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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Mar 24, 2000

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Macros with Variable Number of Arguments

Question:
Is there anyway to have a variable number of arguments passed to a macro? Yes, I know it can be done with inline, but this is for debugging purposes.

Answer:
Yes and no. Standard C and C++ don't support variable number of arguments in a function-like macro. However, the newly approved C99 standard of the C programming language does support function-like macros with a variable number of arguments using the ellipsis (...) notation. The variable arguments (including the separating commas) are "collapsed" into a single extra argument that can be referenced as __VA_ARGS__ within the macro's replacement list.

If you're using a C99 compliant C compiler, you can use this feature. In C++, though, you should use superior techniques such as default parameters, templates, and function objects instead of macros.

DevX Pro
 
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