static, inline, extern — linkage and visibility - MarekBykowski/readme GitHub Wiki

// static at file scope — internal linkage (invisible outside this .c file)
static int counter = 0;        // not accessible from other .c files
static void helper(void) {}    // private function

// static at function scope — persistent across calls
void count(void) {
    static int n = 0;   // initialised once, lives for program lifetime
    printf("%d\n", ++n);
}

// extern — declared here, defined in another .c file
extern int g_system_state;     // tells compiler "trust me, it exists"
extern void uart_init(void);

// inline — hint to compiler to expand inline (no function call overhead)
static inline uint32_t clamp(uint32_t v, uint32_t lo, uint32_t hi) {
    return v < lo ? lo : v > hi ? hi : v;
}
// static inline = inline + internal linkage — the correct pattern for headers
Keyword Scope Effect
static (file) translation unit internal linkage — invisible to linker
static (local) function persistent storage, init once
extern file external linkage — defined elsewhere
inline function hint to expand inline, no call overhead
static inline header inline + no multiple-definition linker error