__FUNCTION__ and friends act weird in Xcode

半腔热情 提交于 2019-12-12 13:03:32

问题


This works

printf("%s body\n",__PRETTY_FUNCTION__);

But this does not (Error Expected ')'):

printf(__PRETTY_FUNCTION__" body\n");

I can't get the IDE to show me what __PRETTY_FUNCTION__ evaluates to to determine why it does not work.


回答1:


__PRETTY_FUNCTION__ is not a macro. It behaves like a static variable created on the fly scoped in that function.

The last paragraph in the link above reads:

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.



来源:https://stackoverflow.com/questions/11142779/function-and-friends-act-weird-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!