The strange syntax of a C debug macro -
can explain me c-syntax below (from tutorial)? understand macro c, "debug %s:%d: " m "\n"
part seems strange me: why there macro parameter 'm' in middle of format part?
#define debug(m, ...) fprintf(stderr, "debug %s:%d: " m "\n", __file__, __line__, ##__va_args__)
c has interesting quirk concatenates string literals. if type
"debug %s:%d: " "hello %s!" "\n"
then compiler sees 1 string: "debug %s:%d: hello %s!\n"
. users can use macro if had printf parameters:
debug("hello %s", username); //on line 94 of myfile.cpp
and macro automatically add file name , line number. format useful because helps know which debug statement logging information.
debug myfile.cpp:94: hello zell
Comments
Post a Comment