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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -