Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I write a cpp macro which takes a variable number of arguments?

CPP macro takes write
0
Posted

How can I write a cpp macro which takes a variable number of arguments?

0

One popular trick is to define the macro with a single argument, and call it with a double set of parentheses, which appear to the preprocessor to indicate a single argument: #define DEBUG(args) (printf(“DEBUG: “), printf args) if(n != 0) DEBUG((“n is %d\n”, n)); The obvious disadvantage is that the caller must always remember to use the extra parentheses. (It is often better to use a bona-fide function, which can take a variable number of arguments in a well-defined way. See questions 7.1 and 7.2 below.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123