liveBook · Manning

Macro retention

As explained in Modern C

Macro retention is the C preprocessing rule that leaves a function-like macro name unexpanded when it is not followed by parentheses.

A function-like macro expands only when its name is followed by parentheses. Without them, macro retention leaves the identifier unchanged, allowing the same name to denote an ordinary function. section 16.1

Protecting a function name

With `#define string_literal(S) string_literal("" S "")`, a declaration written as `char const* string_literal(...)` would be expanded incorrectly. Writing `(string_literal)` prevents expansion because the macro name is not immediately followed by `()`. In `string_literal` used without parentheses, retention preserves the function designator; function decay can then convert it to a function pointer. section 16.1

How Modern C covers it

How deep it goes
Defines the expansion condition and works through protected declarations, stopping short of broader preprocessing internals.
Examples
Uses the string_literal macro, parenthesized declarations, and function-pointer initialization across translation units.
What you can do after
Apply macro retention to keep function identifiers usable when function-like macros have the same name.
How it connects
Connects function-like macros with function decay, function pointers, and preprocessing phases.

Related concepts

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