We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
When i say "complete" i mean that if you are the end user "you don't need to add or modify anything". Not even the call tree.
I'm quite sure we all understand your wish. It's just that we know better than to expect such wishes to come true.
As I said before, not all those nice design patterns lend themselves well to the way a 8051 works. Arbitrary use of function pointers is not a good idea on an 8051.
In my experience libraries aren't used all that much in C51. You've just come across one of the reasons. Another is that 8051 programs are usually small enough that pre-compiled libraries don't offer significant advantage over re-compilation.
In my experience libraries aren't used all that much in C51 I use them a lot HOWEVER, In my experience libraries for which you do not have access to the source aren't used all that much in C51.
Erik