Is it possible for a preprocessor macro to determine whether its argument is a string (literal) or not?
For example:
#define IS_STRING(token) ???
IS_STRING("foo") // expands to 1
IS_STRING(foo) // expands to 0
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.
Yes. But with a small difference in the output:
It will go fine for string literal. For non-strings, it will give compiler error.
Logic: Compiler concatenates string literal automatically, so
"" tokengoes fine, iftokenis a string literal.Here is a related discussion.