Search code examples
cpointersfunction-pointers

Can I use function pointers to static functions like function pointers to non-static functions?


Can I use pointers to static functions like pointers to non-static functions?

Lets say I have:

void (*fp_some_event_handler)(void);

void KeyEventHandler(void){
    // not static
}

static void KeyEventHandlerStatic(void){
    // static
}

Can I use static function pointer just like non-static?

void main() {

    // now I have something like this
    fp_some_event_handler = KeyEventHandler;
    
    // and I want to change some function to static and end with this
    fp_some_event_handler = KeyEventHandlerStatic;
  
}

Solution

  • Whether a function is static is not part of its type but is instead a storage class specifier.

    So you can assign either of the two functions in your sample code to the function pointer fp_some_event_handler.