For example I have a macro:
#define PRINT(int) printf(#int "%d\n",int)
I kinda know what is the result.
But how come #int repersent the whole thing?
I kinda forget this detail. Can anybody kindely give me a hint?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In this context (applied to a parameter reference in a macro definition), the pound sign means to expand this parameter to the literal text of the argument that was passed to the macro.
In this case, if you call
PRINT(5)the macro expansion will beprintf("5" "%d\n", 5);which will print5 5; not very useful; however if you callPRINT(5+5)the macro expansion will beprintf("5+5" "%d\n", 5+5);which will print5+5 10, a little less trivial.This very example is explained in this tutorial on the C preprocessor (which, incidentally, is the first Google hit for c macro pound sign).