By Mohamad 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 * argv[ ] ){
    printf( "The name of the function is: %s ", __func__ );
    /* output:
        The name of the function is: main .*/
    return 0; }

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

void aFunction( ){
    static const char * const __func__ = "aFunction";
    /* __func__ is an array of constant
       characters, which contains the
       function name, in this case
       aFunction .*/}

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