Static keyword in function declaration can be missing in function definition?

后端 未结 5 2050
深忆病人
深忆病人 2021-01-02 03:36

I want to have a static function which I declare in my .c file before defining it:

//file a.c version 1
static int foo();
...
static int foo()
{
...
}
         


        
5条回答
  •  既然无缘
    2021-01-02 04:08

    7.1.1/7:

    The linkages implied by successive declarations for a given entity shall agree. That is, within a given scope, each declaration declaring the same object name or the same overloading of a function name shall imply the same linkage.

    7.1.1/6: (Thanks Steve - this is also needed for the answer to be clear)

    A name declared in a namespace scope without a storage-class-specifier has external linkage unless it has internal linkage because of a previous declaration and provided it is not declared const. Objects declared const and not explicitly declared extern have internal linkage.

    Yes, those two are the same.

    This however is invalid:

    int foo();
    
    static int foo() {
      return 0;
    }
    

提交回复
热议问题