2

Is there anyway to get the calling function name from called function in c++ without modifying the code of calling function ?

asit_dhal
  • 1,239
  • 19
  • 35

2 Answers2

-1

No there isn't. Once code is compiled, all function names and variable names are lost.

There may be debugging info that's kept for debugging purposes that could have that information. But it's not part of the code itself and cannot be accessed through standard C++ methods.

Kyurem
  • 1,839
  • 1
  • 13
  • 7
-1

No, not in standard C++.

Though most compilers have special private functions to get the call-stack though, if you're lucky in a form that allows you to typecast the previous functions address to a callable. However if it's possible, then you have to be careful if the previous call was a member function or not, as member functions need an extra argument for this. If you don't have a reference to that object, then you can't call the member function. And of course, you also have to know all the other arguments types and positions.

In short, it may be possible, but it will not be easy and it will most likely be dangerous.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621