具有函数声明的存储类说明符Storage-Class Specifiers with Function Declarations

在函数声明中,可以使用 static 或 extern 存储类说明符。You can use either the static or the extern storage-class specifier in function declarations. 函数始终具有全局生存期。Functions always have global lifetimes.

Microsoft 专用Microsoft Specific

内部级别的函数声明的含义与外部级别的函数声明的含义相同。Function declarations at the internal level have the same meaning as function declarations at the external level. 这意味着,在翻译单元的剩余部分中,该函数从其声明点可见,即使它是在局部范围内声明的。This means that a function is visible from its point of declaration throughout the rest of the translation unit even if it is declared at local scope.

结束 Microsoft 专用END Microsoft Specific

函数的可见性规则与变量的规则略有不同,如下所示:The visibility rules for functions vary slightly from the rules for variables, as follows:

  • 声明为 static 的函数仅在定义它的源文件中可见。A function declared to be static is visible only within the source file in which it is defined. 同一源文件中的函数可以调用 static 函数,但其他源文件中的函数不能通过名称直接访问它。Functions in the same source file can call the static function, but functions in other source files cannot access it directly by name. 可以在其他源文件中使用相同的名称声明另一个 static 函数,而不会发生冲突。You can declare another static function with the same name in a different source file without conflict.

  • 声明为 extern 的函数在程序中的所有源文件中都可见(除非稍后将此类函数重新声明为 static)。Functions declared as extern are visible throughout all source files in the program (unless you later redeclare such a function as static). 任何函数均可调用 extern 函数。Any function can call an extern function.

  • 默认情况下,省略存储类说明符的函数声明为 externFunction declarations that omit the storage-class specifier are extern by default.

    Microsoft 专用Microsoft Specific

    Microsoft 允许将 extern 标识符重新定义为 static。Microsoft allows redefinition of an extern identifier as static.

    结束 Microsoft 专用END Microsoft Specific

请参阅See Also

C 存储类C Storage Classes