A global variable is a C variable declared outside functions. Its scope extends through the remainder of its source file, and its storage normally persists for the program’s execution. A global variable identifies state rather than an artifact or action. section 9.2
Name global state so its purpose is visible:
- toto_initialized records whether library toto has already been initialized. section 9.2
- onError records an error condition in a file-scope internal variable that is later used during library teardown. section 9.2
- visited_entries records shared data collected by a hash table. section 9.2
TAKEAWAY: File-scope variables are generally frowned upon, but they can be unavoidable. Their names should expose the state they represent rather than disguising it as a constant or action. section 9.2











