名前空間
変種
操作

ファイルスコープ

From cppreference.com
< c‎ | language

識別子を宣言する宣言子または型指定子が、すべてのブロックまたは仮引数リストの外側にある場合、その識別子はファイルスコープを持ち、その有効範囲は翻訳単位の終わりで終了します。

したがって、識別子の宣言(宣言子または型指定子内)をすべてのブロックまたは仮引数リストの外側に配置すると、その識別子はファイルスコープを持つことになります。識別子のファイルスコープは、宣言が出現した翻訳単位の、宣言の箇所から終わりまでです。

[編集]

識別子 a、b、f、g はファイルスコープを持ちます。

#include <stdio.h>
 
int a = 1;
static int b = 2;
 
void f (void) {printf("from function f()\n");}
static void g (void) {printf("from function g()\n");}
 
int main(void)
{
    f();
    g();
 
    return 0;
}
/* end of this translation unit, end of file scope */

実行結果の例

from function f()
from function g()
English 日本語 中文(简体) 中文(繁體)