_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-dependent choices for generic macro interfaces.
- How deep it goes
- Works through function selection and a two-argument minimum, with exercises extending the supported types.
- Examples
- Uses a simplified fabs macro and a two-argument minimum, then exercises integer promotion and signedness macros.
- What you can do after
- Build type-generic macro interfaces that select functions for specified types.
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.
What to know first
- function pointer typeA function pointer is a value that designates a callable function and can be stored, passed, or invoked indirectly.
- function typeA function type specifies the types of inputs and result that a callable value accepts and produces.
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.
Questions about _Generic
What is _Generic?
_Generic is a C11 primary expression that selects one expression from type-associated alternatives according to the type of a controlling expression.
Which Manning books explain _Generic?
Modern C, Third Edition and Modern C.
What should I know before learning _Generic?
Manning books that teach _Generic usually introduce C11, function pointer type, function type and type qualifier first.
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.

