Friday, July 2, 2010

C++: Get Function Name inside the Function

Problem Statement:
Recently I faced a problem in C++ where I wanted to know the name of the function inside the function that was being called...Confused?! I meant, if I am writing the definition of function named Func(), I want to know the name "Func" inside the function.

Solution:
Solution is the use of printf("%s", __FUNCTION__);
The attribute __FUNCTION__ contains the name of the function which is being executed.
This is what we needed, isn't it?

Hope this helps!

No comments: