6

Is it possibly to write a gcc macro that destringifies a string literal argument? I know the opposite is possible with #. Can it be reversed?

For example, __func__ evaluates to the name of the current function in the form of a string literal. Can I remove the double quotation marks around it?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
PSkocik
  • 55,062
  • 6
  • 86
  • 132
  • 3
    [`__func__` is not a macro](http://stackoverflow.com/questions/15305310/predefined-macros-for-function-name-func) – Banex Aug 04 '15 at 10:39
  • I don't think it is possible and you can't spare defining a macro to hold the function name. – Yves Daoust Aug 04 '15 at 10:43

1 Answers1

7

No, it is not possible to convert "foo" to foo using the standard C/C++ preprocessor. If you absolutely need this, you would need to create an external preprocessing program, similar to what Qt does with its moc tool.

Not completely on-topic, but the D language has exactly this functionality - it's called mixins. You can execute arbitrary string processing code at compile time and "paste" the result into your source file with the mixin keyword.

Krzysztof Kosiński
  • 4,062
  • 1
  • 16
  • 22