Hi,
please can someone try this little code snippet with the C51 compiler and tell me why I am getting a "Linker Warning L13: Recursive Call to Segment Foo1, Caller: Foo2"
void foo1(void); void foo2(void); void (*function_pointer)(void) = &foo1; void set_function(void(*p_function_pointer)(void)) { function_pointer = p_function_pointer; } void execute(void) { (*function_pointer)(); } void foo1(void) { set_function(&foo2); } void foo2(void) { bit Linker_Warning_Comes_With_Definition_Of_This_Bit; set_function(&foo1); } void main() { execute(); }
I thought a function pointer it is a good solution for a LCD menu, to switch to other menus
In general, that can be a very good solution but the 8051 does not have sufficiently suitable resources to do it so well.
After a consultant? I'm your man.
Most programs makes implements data-drive menu systems, and then have each menu have an ID that gets processed. It will then let the compiler/linker know that the different menu action functions will never be called recursively.
Thank you! Then I better avoid using function pointers.
Not necessarily - just make sure that you fully understand the issues with function pointers in Keil C51 and follow the advice:
http://www.keil.com/appnotes/docs/apnt_129.asp
http://www.keil.com/support/docs/2429.htm
http://www.keil.com/support/docs/210.htm
http://www.keil.com/support/docs/2379.htm
http://www.keil.com/support/docs/1887.htm
http://www.keil.com/support/docs/1026.htm
http://www.keil.com/support/docs/996.htm