问题
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