Home / Learn Embedded C / The static Keyword in Embedded C

The static Keyword in Embedded C

One keyword, two different jobs: persistent locals, and file-private globals/functions.

Quick summaryOne keyword, two different jobs: persistent locals, and file-private globals/functions.

How to think about this

In plain terms

static has two distinct meanings in C: on a local variable, it persists the value between calls (covered earlier); on a global variable or function, it hides that name from every other file in the project.

Why we use it

A driver's internal helper function or internal state variable usually should not be callable/visible from unrelated files — marking it static enforces that boundary and avoids accidental name clashes across a large firmware project.

Under the hood

static at file scope changes a symbol's linkage from "external" (visible project-wide) to "internal" (visible only within that one .c file) — the compiler/linker then simply refuses to let other files reference it.

Real-world use

  • Driver API design
  • Large multi-file firmware projects

Try it

A static "private" helper vs a public functionC: edit and run

In a real multi-file project, internal_helper could not be called from a different .c file — only public_api could.

Where static appearsWhat it does
Inside a function, on a local variablePersists the variable's value between calls (covered in the C refresher group)
At file scope, on a global variableHides that variable from every other .c file
At file scope, on a functionHides that function from every other .c file

Try it: static persisting a local variable between calls

A static local call counter, the other meaning of staticC: edit and run

Unlike an ordinary local, this count survives from one call to the next — it is initialized only once, not reset every call.

Quick quiz

1. What does static do to a function declared at file scope (outside any other function)?