Sun Studio 12: C++ User's Guide

4.10 Using the Predefined __func__ Symbol for Function Name

When you use -features=extensions, the compiler implicitly declares the identifier __func__ in each function as a static array of const char. If the program uses the identifier, the compiler also provides the following definition where function-name is the unadorned name of the function. Class membership, namespaces, and overloading are not reflected in the name.


static const char __func__[] = "function-name";

For example, consider the following code fragment.


#include <stdio.h>
void myfunc(void)
{
  printf("%s\n", __func__);
}

Each time the function is called, it will print the following to the standard output stream.


myfunc