How do I get the address of the current function?
Tim Writer
writer at me.utoronto.ca
Fri Jun 29 09:54:03 AEST 1990
This is a question that has puzzled me for some time. It may be more
appropriate in comp.unix.wizards but I thought I'd try my luck here first.
Is there a way to get the address of the function which is currently
executing? For example:
char *fcn;
void
foo()
{
...
fcn=current_function();
... do something with fcn
}
You may ask why? Or why not just "fcn=(char *) foo"? I am using setjmp()
and longjmp() to do some error handling. When I use longjmp() it may jump
out of the current function or it may not. Sometimes I want to jump back
to where I used longjmp(). I do this with another setjmp(), longjmp() pair.
However, I can only do the second longjmp() if the first remained within
the current function. In short, I am trying to discern if a longjmp()
would jump into a function that has already returned. I thought that a
function like current_function() would be helpful.
On some systems, if longjmp() encounters a problem, it calls a user
definable function, longjmperror(). Mine doesn't.
If someone has a solution to this longjmp() problem which doesn't involve
something like current_function(), I'd be happy to hear from you. But, I'd
still like to know if it is possible to do something like
current_function().
Thanks in advance.
Tim
P.S I'm using a sparcStation running Sun 4.0.
More information about the Comp.lang.c
mailing list