Type-generic macro
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.
Modern C, Third Edition
A type-generic statement is a statement-form macro expansion whose operations can adapt to the types of its arguments or associated objects.
- How it is used
- Provides shared interfaces for numerical operations, type-dependent expressions, declarations, statements, and initialization.
- How deep it goes
- Explains arithmetic conversions, statement-macro structure, library dispatch, and _Generic selection with concrete expansions and constraints.
- Examples
- Uses a color-channel average, a mutex-protected conditional store, a simplified fabs interface, and const-preserving string search.
- What you can do after
- Build it from scratch using arithmetic conversions or _Generic, and apply it via standard numerical and search interfaces.
Read how Modern C, Third Edition explains type-generic macro →
Modern C
A type-generic macro interface is a macro-based C interface that selects type-specific operations for its arguments.
- How it is used
- Deploys one interface for mathematical or user-defined operations while dispatching to type-specific functions.
- How deep it goes
- Explains _Generic syntax, function-pointer dispatch, arithmetic promotions, and two-argument selection, but defers exhaustive macro coverage.
- Examples
- Uses fabs dispatch, a floating-point minimum macro, maximum-value macros, and type-generic tracing conversions.
- What you can do after
- Builds type-generic C interfaces by combining _Generic selections with macros and type-specific functions.
What to know first
- fused multiply-addA fused multiply-add is an arithmetic operation that multiplies two values, adds a third, and rounds the result once.
- 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
- _Genericuses · _Generic is a C11 primary expression that selects one expression from type-associated alternatives according to the type of a controlling expression.
- tgmath.hpart of · tgmath.h is the C standard header providing type-generic macros that select mathematical functions according to argument types.
- cosine functionalternative to · The cosine function is a periodic trigonometric function that maps a real number or angle to a value between −1 and 1.
- pure functionuses · A pure function is a function whose result depends only on its explicit inputs and whose evaluation has no externally observable side effects.
- macrokind of · A macro is a named, reusable construct that expands into generated code or a sequence of commands when invoked, often during preprocessing, compilation, or application execution.
Questions about type-generic macro
What is type-generic macro?
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.
Which Manning books explain type-generic macro?
Modern C, Third Edition and Modern C.
What should I know before learning type-generic macro?
Manning books that teach type-generic macro usually introduce fused multiply-add, function pointer type, function type and type qualifier first.
What is the difference between type-generic macro and cosine function?
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. The cosine function is a periodic trigonometric function that maps a real number or angle to a value between −1 and 1.
What is type-generic macro a kind of?
Type-generic macro is a kind of macro. A macro is a named, reusable construct that expands into generated code or a sequence of commands when invoked, often during preprocessing, compilation, or application execution.
What is type-generic macro part of?
Type-generic macro is part of tgmath.h. tgmath.h is the C standard header providing type-generic macros that select mathematical functions according to argument types.
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.

