I need some explanation on this code
#define TRACE_PRINT5 (F, X) fprintf(stderr, "%s" STRGY(__LINE__) ":(" #X "): ", X);
I know what does # on beginning, but I don't understand what does on ":(" #X"): "
I need some explanation on this code
#define TRACE_PRINT5 (F, X) fprintf(stderr, "%s" STRGY(__LINE__) ":(" #X "): ", X);
I know what does # on beginning, but I don't understand what does on ":(" #X"): "
This is called "stringizing"; When you add #
, the macro will treat the argument like a string (e.g. getting the name of the thing passed in, instead of the value.)
So for example, if you write:
const char* someString = "abc";
TRACE_PRINT5(something, someString); // let's assume this is on line 10 for __LINE__
That should expand to:
const char* someString = "abc";
fprintf(stderr, "%s" "10" ":(" "someString" "): ", "abc");
(Assuming the STRGY
macro just converts its argument to a string.)
When you put #
before something in a macro it gets the value as string literal.
In your case takes X
as a string literal.
This means that if you pass the variable age
with type int
it will pass put "age" on the place of #X