Hi,
This post is about the classic problem creating pointers to function using the overlay procedure.
The reference in the manual suggest the OVERLAY directive to modify the call tree that is automatically generated by the linker. But what happeneds if we don't know the name of the indirect function the pointer calls? Yes this is true.
Consider the possibility of someone who try to build a lib. And this lib provide a function(funA) that calls an afterwards user defined procedure unknown by the lib function(funA). Here an example
//lib_file.h // ... typedef void (* Tpfun)(void); void module_init (Tpfun pf); void module (void); // ... //lib_file.c static Tpfun pfun; //-------------------------------- void module_init (Tpfun pf) { pfun = pf; } //---------------------- void module (void) { //code // ... pfun(); // code }
In this simple program there is no call to module_init(&..) and it is impossible to know the address/name of the indirect function and so it is also impossible to use the OVERLAY directive(i think). We know only the pointer to function "pfun". We also don't know if the indirect function call other functions. The only way to know the name of the indirect function is when the lib user decide to use the module and initializes the module using the module_init(&..);
But how can we build the lib so the user uses it???
The question is:
1)Is there a way to modify the call tree that is automatically generated by the linker in order to include the indirect function? And if there is no way. 2)How can someone enable the normal way of function call using the stack?
I'm using the eval version C51 8.08
But what happeneds if we don't know the name of the indirect function the pointer calls? Yes this is true.
Then you've just stuck yourself between a rock and a very hard place --- and for no particularly good reason, either. Think really hard if you have to go there.
Not all techniques that work well for keeping big software systems under control are equally applicable for small microcontrollers, particularly the 8051. Passing around pointers to callback functions is definitely one of those. It seriously gets in the way.
Thanks to all for the prompt answer.
I have to say that the way Andy Neil suggests is the way I'm already doing it. But for someone who try to translate code from a compiler to another(like me) is a very difficult procedure. I'm working in education and i find the keil debugger user/student friendly, but still the translation of a library and the whole documentation is a nightmare.
The end user that supplies the callback is the one that builds the complete program, and thus the one that needs to fix up the call tree.
This is true, but i believe that a library must be complete for the end user. How can the user modify the call tree if he doesn't know how the library works. He is just the user.
If the library is written for '51 purposes (no function pointers) the call tree is not the end users job but the linkers.
Erik
View all questions in Keil forum