Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

Track the name of the caller in C/C++ code

Filippo_Spiga
Beginner
4,676 Views
Dear all,I am looking for a easily way to get, inside a C routine, the name of the caller of that routine. Something like that:
void X () {
return MYROUTINE();
}
void MYROUTINE() {
printf ("%s", get_caller_name());
}
"get_caller_name()" is exactly what I am looking for. Is there any internal Intel routine able to do that without change so much the code? I have an alternative idea (playing with #define / #undef) but it requires to change a lot of code...
Any help and suggestion is appreciate!
Regards,
0 Kudos
2 Replies
Andreas_Klaedtke
Beginner
4,676 Views
Have a look at:
http://stackoverflow.com/questions/353180/how-to-i-find-the-calling-function-name
or
http://bytes.com/topic/c/answers/870541-how-know-know-calling-function-name-c-programme

Basically you either have to look through the stack trace, or you have to compile it into the code with the __FUNCTION__ macro.

If you already knew this and there is indeed some "special" feature in the Intel compiler that can achieve this, I would like to know as well.

I hope this is useful to you.
Andreas
0 Kudos
TimP
Honored Contributor III
4,676 Views
-pg inserts a gprof function call which captures that information, as well as timing your function. You could copy and modify that code (presumably subjecting your application to GPL). Just a variation on the preceding advice.
0 Kudos
Reply