Just as the compiler has added custom support for bits, it should also add custom support for function pointers. Here is one idea:
//Saves on storage (1 byte) //Is faster (fixed jump table) //No need to add/remove references in the linker void fn1( void ){}; void fn2( void ){}; void fn3( void ){}; void fn4( void ){}; enumfn MyFnType { fn1, fn2, fn3 }; //must have same signatures MyFnType myFnVar; void FnA(void) { myFnVar = fn1; // do not add fn1 to FnA's call tree myFnVar = fn4; // compiler error } void FnB(void) { (myFnVar)(); // do add fn1,fn2,fn3 to FnB's call tree }
Since only constants are involved, the compiler should be able to optimize the "fp = fp_tab[0];" to a simple move. Instead you get... The 8051 only provides one instruction for reading code memory: MOV A, @A+DPTR. The code generated by the compiler looks pretty optimal to me. Can you suggest a better solution? Jon
How about mov fp,#high(fn1) mov fp+1,#low(fn1)