This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Custom support for function pointers.

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
}

Parents
  • 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

Reply
  • 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

Children