How do I get the address of the current function?

diamond@tkovoa diamond at tkou02.enet.dec.com
Fri Jun 29 12:50:19 AEST 1990


In article <90Jun28.195353edt.19442 at me.utoronto.ca> writer at me.utoronto.ca (Tim Writer) writes:

>Is there a way to get the address of the function which is currently
>executing?

If you know the name of the function, if it is foo, you just say &foo

>char	*fcn;
>void foo() {
>	fcn=current_function();
>}

Your compiler might or might not let you convert a function pointer to a
char pointer.  If it lets you, the result might or might not be usable.
And if you can convert back, it might again be unusable.  Safer is:
void (*fcn)();
void foo() {
	fcn = &foo;
}
-- 
Norman Diamond, Nihon DEC     diamond at tkou02.enet.dec.com
This is me speaking.  If you want to hear the company speak, you need DECtalk.



More information about the Comp.lang.c mailing list