liveBook · Manning

File scope

As explained in Modern C

File scope is the C scope of an identifier declared outside any function or block and extending to the end of the source file.

int main(void);
double A[5];
size_t i;


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":3}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":8}],[{\"line\":0,\"ch\":9},{\"line\":0,\"ch\":13}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":6}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":6}]]"}
!@%STYLE%@!

This listing places declarations outside any function or block, providing a concrete view of file-scope identifiers. section 2.2

In C, an identifier has file scope when its declaration appears outside every function and block. Its visibility begins at that declaration and continues to the end of the source file. Identifiers with file scope are often called globals. section 2.2

TAKEAWAY

  • File scope is not limited by a pair of braces. section 2.2
  • Block scope instead limits visibility to the associated block, such as the block belonging to a for construct. section 2.2

How Modern C covers it

How deep it goes
Defines file scope and contrasts it with block scope through declaration locations and visibility ranges.
Examples
Uses main and other declarations written outside function or block boundaries to illustrate file-scope visibility.
What you can do after
Evaluate/understand whether an identifier remains visible through the end of a C source file.
How it connects
Connects file scope with block scope, identifiers, declarations, and globals.

Also explained in

Compare how 2 books explain file scope →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.