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
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.