In the C language, __FUNCTION__
can be used to get the current function's name. But if I define a function named a() and it is called in b(), like below:
b() { a(); }
Now, in the source code, there are lots of functions like b() that call a(), e.g. c(), d(), e()...
Is it possible, within a(), to add some code to detect the name of the function that called a()?
Further:
Description. A Function Caller block calls and executes a function defined with a Simulink Function block or an exported Stateflow® function. Using Function Caller blocks, you can call a function from anywhere in a model or chart hierarchy.
The calling function supplies the input (the actual arguments), which are then used by the called function to process the parameters because it has the definition, carry out the instructions, and return whatever that should be returned. The function that another function calls is known as the called function.
The C Caller supports code generation. In the code generated from your model, each execution of a C Caller block corresponds to a call to the external C function associated with the block.
There's nothing you can do only in a.
However, with a simple standard macro trick, you can achieve what you want, IIUC showing the name of the caller.
void a() { /* Your code */ } void a_special( char const * caller_name ) { printf( "a was called from %s", caller_name ); a(); } #define a() a_special(__func__) void b() { a(); }
You can do it with a gcc builtin.
void * __builtin_return_address(int level)
The following way should print the immediate caller of a function a().
Example:
a() { printf ("Caller name: %pS\n", __builtin_return_address(0)); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With