liveBook · Manning

Naming policy

As explained in Modern C, Third Edition

A naming policy is a consistent set of rules for choosing names for program entities.

A naming policy sets consistent rules for choosing names for every identifier: types, members, variables, enumerations, macros, functions, and function-like macros. Separate technical restrictions from semantic conventions; both affect correctness and maintainability. section 9.2

A declaration exposes naming risks

double memory_sum(size_t N, size_t I, double strip[N][I]); Names such as N, I, and strip may collide with macros, predefined meanings, implementation identifiers, or future standard-library names. A more distinctive alternative is: double p99_memory_sum(size_t p00_n, size_t p00_i, double p00_strip[p00_n][p00_i]); section 9.2

Apply these restrictions especially to identifiers visible in header files:

  • Avoid names beginning with an underscore followed by another underscore or a capital letter; these are reserved for extensions and internal use. section 9.2
  • Treat leading-underscore file-scope identifiers and enum, struct, and union tags as reserved. section 9.2
  • Use all-capital names for macros, and avoid predefined identifiers, C library names, names beginning with str or E, and names ending in _t. section 9.2

How Modern C, Third Edition covers it

How deep it goes
Defines identifier categories, namespace hazards, and reserved-name patterns; stops short of listing every restriction.
Examples
Uses C declarations, confusing identifier pairs, and alternative names to demonstrate collision avoidance and distinguishability.
What you can do after
Apply it by choosing consistent, conforming identifiers, especially in declarations visible through header files.
How it connects
Connects naming policy to header files, macro definitions, reserved identifiers, namespaces, and portability.

Also explained in

Compare how 2 books explain naming policy →

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.