c89 gcc 4.7.4
I was just experimenting with macros like these:
#define LOG_INFO_1(fmt, ...) printf(fmt, __VA_ARGS__)
#define LOG_INFO_2(...) printf(__VA_ARGS__)
And using like this:
LOG_INFO_1("%s:%d", __func__, __LINE__);
LOG_INFO_2("%s:%d", __func__, __LINE__);
The output gives exactly the same format. I am just wondering what is the advantage of having the fmt argument in my first macro? It doesn't seem to be really needed. How could I make use of it?
LOG_INFO_1("just a simple string"). When you do that,LOG_INFO_1will result in a compiler error, due to the trailing comma in the call toprintf(since__VA_ARGS__expands to the empty string in that case), whereasLOG_INFO_2will expand correctly.