By Wael

Last updated :

Posted :

What is __func__ in c ?

__func__ is a predefined identifier , it was defined as part of the c99 standard , and it is used to get the name of a function.

The __func__ identifier is used to get the name of a function
#include <stdio.h>
/* 
    include the stdio header in order
    to use the printf function .
*/


int main(int argc, char const *argv[])
{
    printf("the name of the function is : %s ", __func__);
    // output : the name of the function is : main
    /* Prints the name of the main function using  __func__*/
    
    return 0;
}

__func__ can be thought of as being defined inside a function as follow :

void aFunction()
{
    static const char *const __func__ = "aFunction"; 
    // __func__ contains the function name
}

The __func__ identifier must not be redefined , if this is done the behaviour is not defined .