callback functions

In C/C++ can a called function have an ability to know the name of the calling function?

May be, by accessing the stack or any other way? Please note that this is not a design question (I am not trying to design the architecture), but more of a C/C++ functionality question.
Last edited on
You want the callback to know who called it so that it changes its behaviour depending on that, or you want this for debugging reasons? If it's the former, I'd suggest writing different callbacks. If it's the latter, you could pass something to the callback that shows who called it.
Not portably. It can be done using [system [debugging features]] to get the stack trace, if there are debugging symbols available. Or you can have the caller pass its own name to the callback through a string.
Topic archived. No new replies allowed.