The __func__ predefined identifier
The C99 predefined identifier
__func__ makes a
function name available for use within the function. Immediately following
the opening brace of each function definition, __func__ is
implicitly declared by the compiler. The resulting behavior is as
if the following declaration had been made: static const char __func__[] = "function-name";where function-name is
the name of the lexically-enclosing function. The function name is
not mangled.
Beginning of C++ only.
The function name is qualified with the enclosing class
name or function name. For example, if foo is a member
function of class X, the predefined identifier of foo is
X::foo. If foo is defined within
the body of main, the predefined identifier of foo is main::X::foo.
The
names of template functions or member functions reflect the instantiated
type. For example, the predefined identifier for the template function foo instantiated
with int, template<classT> void foo() is foo<int>.
End of C++ only.
For debugging purposes, you can explicitly use the
__func__ identifier
to return the name of the function in which it appears. For example: #include <stdio.h>
void myfunc(void) {
printf("%s\n", __func__);
printf("size of __func__ = %d\n", sizeof(__func__));
}
int main() {
myfunc();
} The output of the program is: myfunc
size of __func__ = 7Related information