In the following code, get_func_name()
can be a system call, a library call, or a function defined my myself. Without taking any parameter, how can I let get_func_name()
print out the name of the calling function, without using the information from the stack?
Also, besides the name of the caller, can I print out anything in get_func_name()
that can uniquely identify the caller?
void get_func_name(){
/*What magic goes here?*/
}
void func2(){
func3();
get_func_name(); /*Should print out "func2()"*/
}
void func1(){
func2();
get_func_name(); /*Should print out "func1()"*/
}
void main(){
func1();
get_func_name(); /*Should print out "main()"*/
}