Examples of predefined macros

This example illustrates use of the __FUNCTION__ and the __C99__FUNC__ macros to test for the availability of the C99 __func__ identifier to return the current function name:
#include <stdio.h>  

#if defined(__C99__FUNC__) 
#define PRINT_FUNC_NAME() printf (" In function %s \n", __func__); 
#elif defined(__FUNCTION__) 
#define PRINT_FUNC_NAME() printf (" In function %s \n", __FUNCTION__); 
#else 
#define PRINT_FUNC_NAME() printf (" Function name unavailable\n"); 
#endif  

void foo(void);  

int main(int argc, char **argv) 
{ 
   int k = 1; 
   PRINT_FUNC_NAME(); 
   foo(); 
   return 0; 
}  

void foo (void) 
{ 
   PRINT_FUNC_NAME(); 
   return; 
}
The output of this example is:
In function main
In function foo

C++ only This example illustrates use of the __FUNCTION__ macro in a C++ program with virtual functions.

CCNX08C

#include <stdio.h>
class X { public: virtual void func() = 0;};

class Y : public X {
   public: void func() { printf("In function %s \n", __FUNCTION__);}
};

int main() {
  Y aaa;
  aaa.func();
}
The output of this example is:
In function Y::func()