Is there a way to remove quotes in a C macro?

syvex picture syvex · Apr 18, 2012 · Viewed 10.9k times · Source

Suppose I want to un-stringify the macro argument which should transform "text" to text.

#define UN_STRINGIFY(x) /* some macro magic here */

Now calling this macro will remove "" from its argument

UN_STRINGIFY("text") // results in ----> text

This would be the opposite of macro stringification:

#define STRINGIFY(x) #x

Is this possible, or am I playing with macro evilness?

Answer

ThiefMaster picture ThiefMaster · Apr 18, 2012

It's not possible. And that's probably a good thing: If you pass a string you assume you can put pretty much everything in it. Un-stringifying it would suddenly result in the compiler actually caring about the contents of that string.