C preprocessor IV: VA Args

Post by Nico Brailovsky @ 2013-09-10 | Permalink | Leave a comment

And things just got even more awesome in our preprocessor series: if just passing a known number of parameters is not cool enough for you you can use a variable number of arguments on a macro definition too. This is very useful to implement printf style debug macros which get replaced by no tokens on a release build. Or to make debugging a bit more complicated, your choice.

#define DEBUG(fmt, ...) printf(fmt, VA_ARGS);

Combining this with stringify will provide you hours of fun. Combining this with token pasting... well, that's just evil.