我试图在编译时将 __PRETTY_FUNCTION__
附加到 c 字符串前缀。但它无法编译。而如果我用 __FILE__
来做,它就不会失败。
const char* s1= "Prefix" __FILE__; // works
const char* s2= "Prefix" __PRETTY_FUNCTION__; // compilation error
error: expected ',' or ';' before '__PRETTY_FUNCTION__'
const char* s2 = "Prefix" __PRETTY_FUNCTION__;
^~~~~~~~~~~~~~~~~~~
我正在使用 gcc 和 clang。 我错过了什么吗?
最佳答案
来自 GCC documentation for __PRETTY_FUNCTION__
:
[
__func__
and__PRETTY_FUNCTION__
] are variables, not preprocessor macros, and may not be used to initialize char arrays or be concatenated with string literals.
关于C++:将 __PRETTY_FUNCTION__ 附加到 c 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51747622/