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

后端 未结 5 2065
深忆病人
深忆病人 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:07

    The static attribute changes the visibility to the compilation unit. This allows to use the same name in different files for different purposes. You should use the static only once. If you have a prototype, you must do here.

    When you are asking for C++ you should not use static but anonymous namespace to make the symbold private for the compilation unit:

    namespace {
        int foo();
    }
    
    void bar()
    {
        foo();
    }
    

提交回复
热议问题