_Generic
_Generic is a C11 primary expression that selects one expression from type-associated alternatives according to the type of a controlling expression.
Modern C, Third Edition
A generic selection is a C11 expression construct that selects one expression from a set based on the type of a controlling expression.
- How it is used
- Provides compile-time type-based selection for interfaces such as type-generic macros.
- How deep it goes
- Defines the expression form and works through function dispatch, then introduces two-argument selection and its conversion concerns.
- Examples
- Uses a `fabs` dispatch macro and a two-argument `min` interface; proposes extensions to complex and integer types.
- What you can do after
- Apply it via `_Generic` to dispatch a macro to functions selected by argument type.
Modern C
_Generic is a C11 primary expression that selects one expression from type-associated alternatives based on the type of a controlling expression.
- How it is used
- Uses type-based selection to build function-like macro interfaces such as generic absolute value, minimum, and tracing utilities.
- How deep it goes
- Defines syntax and dispatches complete macro examples, then stops short of broader macro-programming complications.
- Examples
- Demonstrates fabs dispatch, floating-point minimum, maximum-value selection, and tracing format or value conversion.
- What you can do after
- Apply _Generic through macros to select type-specific functions, expressions, format strings, or conversions.
Related concepts
- type-generic macroused by · A type-generic macro is a macro-based interface whose expansion selects or adapts operations according to the types of its arguments or associated objects.
- type-generic interfaceimplements · A type-generic interface is a programming interface that selects or adapts operations according to the types of its arguments or associated values.
- function-like macroused by · A function-like macro is a macro invoked with function-like syntax that accepts token input and expands or transforms it into generated source.
- inline functionuses · An inline function is a function defined or designated for incorporation at its use site, either syntactically or through compiler substitution, rather than necessarily invoked through an ordinary call.
- type traituses · A type trait is a compile-time facility that queries or transforms a type and produces a result representing the requested property or type.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

