What is C local function declaration mechanism?

前端 未结 3 1189
终归单人心
终归单人心 2021-01-21 09:07

Local function declaration seems to be permitted in gcc, and I found a discussion on this: Is there any use for local function declarations?

However, my question is: is

3条回答
  •  终归单人心
    2021-01-21 09:25

    To fix the second example you need to declare f in main with proper return type

    int main(void) {
        void f(void);  // function declaration
        f(); // calling function
    }  // scope of f ends here
    
    void f(void) {} 
    

    This way you inform compiler what to look for, and later it finds it indeed. Hope it helps.

提交回复
热议问题