How can I write a cpp macro which takes a variable number of arguments?
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.