`extern` — C Keyword
`extern` — C Keyword
The extern keyword in C: declares a variable or function defined in another translation unit.
`extern` — C Keyword
The extern keyword in C: declares a variable or function defined in another translation unit.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
extern (C)Declares that a variable or function is defined elsewhere (another .c file), giving it external linkage. No storage is allocated by a declaration.
extern Type name; /* declaration, no definition */
extern return-type func(params); /* declaration of external function */
/* --- config.c --- */
/* int g_timeout = 30; */ /* definition */
/* --- main.c --- */
#include <stdio.h>
extern int g_timeout; /* declaration: defined in config.c */
int main(void) {
/* printf("%d\n", g_timeout); */ /* uses definition from config.c */
printf("extern demo\n");
return 0;
}
extern already has external linkage by default in C.extern references at link time; a missing definition is a linker error.int main() {
// Pick one facility from this reference page.
// Write the smallest program that exercises its main precondition,
// complexity rule, or lifetime constraint before scaling up.
return 0;
}