Rodney Lott <email@example.com> wrote:
Without cooperation of the calling function there isn’t really an
easy way to do this.
You could try examining the call stack for the return location,
and then comparing this to a map file generated at compile time… and
figure things out from there – could be a bit messy though, as Watcom
by default uses register-based calling conventions, so I’m not sure
how complete the stack frames are, or how easy to decode… should still
Easiest would be to have all the calling functions pass in a string of
their name when they call you.
I was wondering if there is any way within a C program to determine the name
of a function that has called another function. So, let’s say we have 3
functions: foo(), bar() and baz(). These functions call a function called
quux(). Is there a way that I could, from quux(), determine which of the
three functions called me? I was curious if this was possible, since there
are macros like FILE and LINE that indicate what file or line you
are dealing with exist. I know that what I am asking can be done by using a
global variable that everyone can set, but I was wondering if there is a
more elegant way. Thus, if quux() was a function that was used for printing
out errors, I could find out the function name where quux() was called from
and that would aid the composition of an error message.
The FILE and LINE are pre-processor directives, filled in at that
point. There isn’t, and can’t be such a function for calling routine.
(i.e. Compiler can’t now when, for instance, a function pointer might
be used to call your function.)
QNX Training Services
Please followup in this newsgroup if you have further questions.