这行得通
printf("%s body\n",__PRETTY_FUNCTION__);
但这不是(错误 Expected ')'
):
printf(__PRETTY_FUNCTION__" body\n");
我无法让 IDE 向我展示 __PRETTY_FUNCTION__
的计算结果以确定它为何不起作用。
最佳答案
__PRETTY_FUNCTION__
is not a macro .它的行为类似于在该函数范围内动态创建的静态变量。
上面链接的最后一段是这样的:
These identifiers are not preprocessor macros. In GCC 3.3 and earlier, in C only,
__FUNCTION__
and__PRETTY_FUNCTION__
were treated as string literals; they could be used to initialize char arrays, and they could be concatenated with other string literals. GCC 3.4 and later treat them as variables, like__func__
. In C++,__FUNCTION__
and__PRETTY_FUNCTION__
have always been variables.
关于c++ - __FUNCTION__ 和 friend 在 Xcode 中表现得很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11142779/