静态

静态函数 属于 C

{other: "%{count} 个练习"}

关于 静态函数

函数默认具有外部链接,可以被项目中的任何其他文件调用。 关于链接的更多内容,请参阅链接概念。 static函数只能在定义它的源文件内被调用。

例如

// file scope, internal linkage
// can only be called from within this file
static void some_function()
{
    // code snipped
}

// file scope, external linkage by default
// can be called from any other file in the project
int main()
{
    // code snipped
}

即使一个函数在头文件中声明,如果它被定义为static,也无法从它的源文件之外调用。 源文件可以包含该头文件,调用头文件中声明的static函数,并通过编译,但链接器会找不到该static函数的定义。 在源文件中标记为static的函数不应在其头文件中声明。

通过 GitHub 编辑 该链接会在新窗口或标签页中打开