blob: 1e49b1cfcab8510c1bec2b30b744c43cd84c709e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
<h1 id="firstHeading" class="firstHeading">File scope</h1> <p>If the declarator or type specifier that declares the identifier appears outside of any block or list of parameters, the identifier has file scope, which terminates at the end of the translation unit.</p>
<p>So, placement of an identifier's declaration (in a declarator or type specifier) outside any block or list of parameters means that the identifier has file scope. File scope of an identifier extends from the declaration to the end of the translation unit in which the declaration appears.</p>
<h3 id="Example"> Example</h3> <div class="t-example">
<p>Identifiers a, b, f, and g have file scope.</p>
<div class="c source-c"><pre data-language="c">#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 */</pre></div> <p>Possible output:</p>
<div class="text source-text"><pre data-language="c">from function f()
from function g()</pre></div> </div> <div class="_attribution">
<p class="_attribution-p">
© cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
<a href="https://en.cppreference.com/w/c/language/file_scope" class="_attribution-link">https://en.cppreference.com/w/c/language/file_scope</a>
</p>
</div>
|