Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it ever possible to get the current (member) function name in C++?

Tags:

c++

I don’t know much about RTTI, but I believe that thanks to that you can retrieve the name of variables at run-time. Is it possible to retrieve the name of the function the thread is currently running ?

like image 619
qdii Avatar asked Dec 09 '22 03:12

qdii


2 Answers

C++11 standardized __func__ for the current function.

Various compilers support variations of __FUNCTION__, __PRETTY_FUNCTION__, and others.

like image 52
Xeo Avatar answered Dec 29 '22 00:12

Xeo


If you're doing GNU compatible stuffs, you may want to try backtrace.

like image 42
starrify Avatar answered Dec 28 '22 22:12

starrify