4

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 ?

qdii
  • 12,505
  • 10
  • 59
  • 116

4 Answers4

12

C++11 standardized __func__ for the current function.

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

Xeo
  • 129,499
  • 52
  • 291
  • 397
2

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

starrify
  • 14,307
  • 5
  • 33
  • 50
0

No.

C++'s run-time type identification allows you to figure out the type of an object, but not the name of the method you're currently in.

unwind
  • 391,730
  • 64
  • 469
  • 606
0

No, it is not possible. C++ does not support reflection (neither static nor dynamic) (like e.g. C#). You would need some preprocessor magic to emulate that.

Apart from that, there is not necessarily a notion of a function/method name during run-time (this only available as debugging information if you compiled your sources with the corresponding flags).

Andre
  • 1,577
  • 1
  • 13
  • 25