liveBook · Manning

Namespace collision

As explained in Modern C, Third Edition

A naming conflict is an unintended collision between names declared by different parts of a C program, library, implementation, or macro environment.

A namespace collision occurs when names declared by application code, libraries, implementations, or macros interfere unexpectedly. C makes these conflicts especially troublesome because reserved identifiers may remain harmless until a new standard, compiler, client machine, or system upgrade changes the surrounding environment. section 9.2

Reduce collision risk by applying explicit naming rules:

  • Expose only types and functions intended as the public API; avoid polluting the global identifier space. section 9.2
  • Avoid reserved identifiers, including many C-library names, names beginning with str or E, and names ending in _t. section 9.2
  • Use distinctive prefixes for library interfaces and internals, and remember that macros can collide with structure members and function parameters. section 9.2

Prefix public and internal names

A generic interface such as memory_sum(size_t N, size_t I, double strip[N][I]) exposes short names. A prefixed form—p99_memory_sum(size_t p00_n, size_t p00_i, double p00_strip[p00_n][p00_i])—separates the public API from implementation-oriented names and reduces accidental collisions.

How Modern C, Third Edition covers it

How deep it goes
Explains reserved names, exposure boundaries, prefixes, and macro-sensitive members and parameters, without detailing compiler name-resolution internals.
Examples
Uses prefixed and unprefixed function signatures plus examples of identifiers that are recognizable or difficult to distinguish.
What it assumes
Assumes familiarity with C identifiers, macros, functions, structures, headers, and application programming interfaces.
What you can do after
Apply naming prefixes and limited API exposure to reduce collisions in C libraries and shared code.
How it connects
Connects identifier naming with C library functions, macros, structure members, function parameters, APIs, headers, and portability.

Also explained in

Compare how 3 books explain namespace collision →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.