Define A Macro In C With A Variable Number Of Arguments

Say you want to wrap a function like printf() (which receives a variable number of arguments) with a macro. This is how to do it:


#define PRINT_DEBUG(fmt, args...)  printf("DBG:"fmt, ##args)

That is, declare them as args… and use them with ##args.

Note: The word args has nothing special, you could similarly use somethingelse… and ##somethingelse. Just in case you were wondering ;-)

Leave a Reply