Example:
I have an integer variable called menino
, how do I print to a printf
the name of this variable, ie "menino"
Example:
I have an integer variable called menino
, how do I print to a printf
the name of this variable, ie "menino"
You can do with a trick on the preprocessor. I found this macro in answer in SO :
#define DUMP(varname) fprintf(stderr, "%s = %x", #varname, varname);
The secret is in #
that transforms the text of the code (part of the written code) into literal text (a string ) that can be used by the code. Obviously you do not have to use strderr
or even fprintf
.
int i = 0;
DUMP(i); //será convertido para fprintf(stderr, "%s = %x", "i", i);
I see little utility for this in normal codes.