What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__ in C/C++?


Here we will see what are the differences between __FUNCTION__, __func__ and the __PRETTY_FUNCTION__ in C++.

Basically the __FUNCTION__ and __func__ are same. Some old versions of C and C++ supports __func__. This macro is used to get the name of the current function. The _PRETTY_FUNCTION__ is used to return the detail about the function. Using this we can get which function is used, and in which class it is belonging, etc.

Example

#include<iostream>
using namespace std;
class MyClass{
   public:
      void Class_Function(){
         cout << "The result of __PRETTY_FUNCTION__: " << __PRETTY_FUNCTION__ << endl;
      }
};
void TestFunction(){
   cout << "Output of __func__ is: " << __func__ << endl;
}
main() {
   cout << "Output of __FUNCTION__ is: " << __FUNCTION__ << endl;
   TestFunction();
   MyClass myObj;
   myObj.Class_Function();
}

Output

Output of __FUNCTION__ is: main
Output of __func__ is: TestFunction
The result of __PRETTY_FUNCTION__: void MyClass::Class_Function()

Updated on: 30-Jul-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements