[英]Is the static keyword needed in both the declaration and the definition of a static function in C?
In C, inside a implementation file, when forward declaring a static function in that same file, is the static keyword needed in both the declaration (prototype) and the definition of the function?
如果您在原型中包含static
(前向聲明),那么您可以在實際定義中省略該關鍵字(然后隱含)。 但是,如果您在原型中沒有static
但將其包含在定義中,那么您處於非標准 C 的領域。
例如,以下代碼是非標准的:
#include <stdio.h>
void foo(void); // This declares a non-static function.
int main()
{
foo();
return 0;
}
static void foo(void)
{
printf("Foo!\n");
}
clang-cl 編譯器對此發出警告:
警告:將非靜態“foo”重新聲明為 static 是 Microsoft 擴展 [-Wmicrosoft-redeclare-static]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.