Actually there is one pretty common method to achieve this. Just define a macro #define bar() debug_bar(__func__) and then write a small function debug_bar(char *funct_name) which will use this string as you want and will call original bar() function.
-Vinit On Thu, Mar 5, 2009 at 12:49 PM, Ravi Sankar <[email protected]> wrote: > Hi, > > I would like to know how can I get the function name of the caller in c?. > > Like > // c code > > void foo(void) > { > > bar(); > } > > void bar(void) > { > // who is my caller? > } > > I don't want to change the caller function code to add arguments etc. > Even I don't have access to the caller function source code. > > Thanks for your help. > > -- > --, > BR, > Ravi Sankar Guntur. >
