J
jake1138
I couldn't find an example of this anywhere so I post it in the hope
that someone finds it useful. I believe this is compiler specific (I'm
using gcc), as C99 defines __VA_ARGS__. Comments are welcome.
This will print the file name and line number followed by a format
string and a variable number of arguments. The key here is that you
MUST have a space between __LINE__ and the last comma, otherwise
__LINE__ gets eaten by the ## if args is empty. It took me awhile to
figure that out.
#define DEBUGLOG(fmt, args...) printf("%s(%d)"fmt , __FILE__ ,
__LINE__ , ## args)
I'm curious, does anyone know if the equivelant can be done using
__VA_ARGS__?
that someone finds it useful. I believe this is compiler specific (I'm
using gcc), as C99 defines __VA_ARGS__. Comments are welcome.
This will print the file name and line number followed by a format
string and a variable number of arguments. The key here is that you
MUST have a space between __LINE__ and the last comma, otherwise
__LINE__ gets eaten by the ## if args is empty. It took me awhile to
figure that out.
#define DEBUGLOG(fmt, args...) printf("%s(%d)"fmt , __FILE__ ,
__LINE__ , ## args)
I'm curious, does anyone know if the equivelant can be done using
__VA_ARGS__?