How to call the static function from another c file?

前端 未结 6 1651
谎友^
谎友^ 2021-02-07 22:48

I want to call a static function from another C file. But it always show \"function\" used but never defined.

In ble.c

6条回答
  •  旧时难觅i
    2021-02-07 23:12

    Static function has internal linkage and it can be called only by functions written in the same file. However if you want to call static function from another file , we have a trick in C. Fallow the steps. 1. Create a function pointer globally in ble.c and define it.

    (void)(*fn_ptr)();
    static void bt_le_start_notification(void)
    {
        WPRINT_BT_APP_INFO(("bt_le_start_notification\n"));
        fn_ptr=bt_le_start_notification;
    
    }
    

    in main.c extern the function pointer

     #include "ble.h"
    extern fn_ptr;
    
    void application_start( void )
    {
      fn_ptr();
    }
    

    Hope it will be useful.

提交回复
热议问题