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
Yes. But with a small difference in the output:
#define IS_STRING(token) "" token
It will go fine for string literal. For non-strings, it will give compiler error.
Logic: Compiler concatenates string literal automatically, so "" token
goes fine, if token
is a string literal.
Here is a related discussion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With