I want to implement a C/C++ variadic logging macro, which contains __FILE__
and __LINE__
information.
This is my simple implementation:
#include <stdio.h>
#define MYLOG(format, ...) printf("%s:%d " format, __VA_ARGS__)
The only issue is that, this macro doesn't compile when my logging has no parameters, for example:
MYLOG("hello world");
I've read some wikis and blogs, there's a solution for GCC compiler:
#include <stdio.h>
#define MYLOG(format, ...) printf("%s:%d " format, ##__VA_ARGS__)
But is there a more standard way to implement this macro working on GCC/Clang/MSVC compilers?