C Programming • C17 baseline, standards-specific features labeled
Declarations, Definitions, Scope, and Linkage
Reason about where a name is visible, which object it denotes, and whether it is shared across files.
Scope controls where an identifier can be used. Linkage determines whether declarations in different scopes or translation units refer to the same entity. Storage duration describes an object lifetime. These concepts are related but not interchangeable; static at file scope gives internal linkage, while extern commonly refers to an external definition.
Example
/* module.c */
static int module_state; /* internal linkage */
int public_count(void) {
return module_state;
}
/* app.c */
int public_count(void); /* declaration */
What to expect
public_count can be called from another translation unit; module_state cannot be named from there.
Key idea: Prefer explicit interfaces and limit file-scope state; accidental multiple definitions are usually a build-design problem.