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

RE: enabling OVERLAY only for some func

Bahri Okuroglu

Turning off overlaying to use function pointers has a heavy ram size price.

Since function pointers are tricky to use, I suggest the following technique. This technique has 2 advantages. The call tree is built automatically by the linker. Also you need only save and pass a char enum instead of a larger function pointer. This usually offsets the cost of the extra array evaluation.

extern char Fn1( char, char );
extern char Fn2( char, char );
extern char Fn3( char, char );

typedef char FnT( char, char );
enum {eFn1, eFn2, eFn3 };
FnT* code pFns[] = { &Fn1, &Fn2, &Fn3 };

void main( void )
{
  char a = (*pFns[ eFn2 ])( 1, 100 );
}

Parents
  • Your case is the poster boy for my approach.

    typedef void KeyHdlrT( void );
    enum {khConsole, khMenu, khOther };
    KeyHdlrT* code pKeyHdlrs[] =
     { &main_console_keyboard_handler,
       &main_menu_keyboard_handler,
       &main_other_keyboard_handler };
    
    BYTE KeyHdlr;
    
    
    void OnKey( void )
    {
      (*pKeyHdlrs[ KeyHdlr ])(); 
    }
    
    void OnEnter( void )
    {
      KeyHdlr = khMenu;
    }
    
    void main( void )
    {
      KeyHdlr = khConsole;
    
      //more code
    }
    <\pre>
    
    

Reply
  • Your case is the poster boy for my approach.

    typedef void KeyHdlrT( void );
    enum {khConsole, khMenu, khOther };
    KeyHdlrT* code pKeyHdlrs[] =
     { &main_console_keyboard_handler,
       &main_menu_keyboard_handler,
       &main_other_keyboard_handler };
    
    BYTE KeyHdlr;
    
    
    void OnKey( void )
    {
      (*pKeyHdlrs[ KeyHdlr ])(); 
    }
    
    void OnEnter( void )
    {
      KeyHdlr = khMenu;
    }
    
    void main( void )
    {
      KeyHdlr = khConsole;
    
      //more code
    }
    <\pre>
    
    

Children
No data