Error in __func__
#include <stdio.h>
char* __func__ = "hello";
void myfunc(void)
{
printf("%s\n", __func__开发者_StackOverflow中文版);
}
int main()
{
myfunc();
}
The above snippet gives error: expected identifier or ‘(’ before ‘__func__’
. Why?
You know that __func__
is a predefined identifier (at least as of C99, see here for details)? Why are you using it? I'm guessing you get the error at the __func__
definition line, because of that.
Technically the behaviour is undefined as per C99 because you explicitly declare __func__
.
J.2 Undefined behavior
The behavior is undefined in the following circumstances:...
The identifier
__func__
is explicitly declared (6.4.2.2).
And it is known that undefined behaviour means anything can happen [and that includes compilation error as well]
精彩评论