Type-generic interface
A type-generic interface is a programming interface that selects or adapts operations according to the types of its arguments or associated values.
Modern C, Third Edition
Type-generic programming is a programming technique that selects or adapts operations according to the types of values involved.
- How it is used
- Provides shared C interfaces that adapt operations to argument types and qualifications.
- How deep it goes
- Explains macro expansion, arithmetic conversions, function selection, and const preservation through concrete interfaces and their constraints.
- Examples
- Uses gray-value arithmetic, fabs dispatch, const-preserving strstr calls, and exercises extending generic macros.
- What you can do after
- Builds type-generic macro interfaces using arithmetic conversions or _Generic to select functions.
Read how Modern C, Third Edition explains type-generic interface →
Modern C
Type-generic programming is a technique for providing one interface that selects or adapts behavior according to the types of its inputs.
- How it is used
- Deploys macros with _Generic to present one type-safe interface over several type-specific functions or values.
- How deep it goes
- Explains _Generic selection and multi-argument dispatch, then demonstrates practical macro utilities without developing every language corner case.
- Examples
- Uses fabs dispatch, floating-point minimum, maximum-value selection, and tracing formats and conversions as concrete implementations.
- What you can do after
- Builds type-generic C11 macro interfaces that dispatch to typed functions or expressions while avoiding unnecessary macro evaluation hazards.
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.
- _Generic_Generic is a C11 primary expression that selects one expression from type-associated alternatives according to the type of a controlling expression.
Related concepts
- _Genericimplemented by · _Generic is a C11 primary expression that selects one expression from type-associated alternatives according to the type of a controlling expression.
- interfacekind of · An interface is a contract or boundary that specifies the operations, members, or data shape a type or component exposes, without prescribing its complete implementation.
- atomic typecontrasts with · An atomic type is a type whose supported accesses and operations are indivisible with respect to concurrent execution and provide defined synchronization semantics.
- tgmath.huses · tgmath.h is the C standard header providing type-generic macros that select mathematical functions according to argument types.
- type-generic macrohas part · 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.
Questions about type-generic interface
What is type-generic interface?
A type-generic interface is a programming interface that selects or adapts operations according to the types of its arguments or associated values.
Which Manning books explain type-generic interface?
Modern C, Third Edition and Modern C.
What should I know before learning type-generic interface?
Manning books that teach type-generic interface usually introduce C11, function pointer type, function type and _Generic first.
What is the difference between type-generic interface and atomic type?
A type-generic interface is a programming interface that selects or adapts operations according to the types of its arguments or associated values. An atomic type is a type whose supported accesses and operations are indivisible with respect to concurrent execution and provide defined synchronization semantics.
What is type-generic interface a kind of?
Type-generic interface is a kind of interface. An interface is a contract or boundary that specifies the operations, members, or data shape a type or component exposes, without prescribing its complete implementation.
What are the parts of type-generic interface?
Type-generic interface includes type-generic macro.
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.

