liveBook · Manning

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.

How 2 Manning books explain it

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.

Read how Modern C explains type-generic macro →

What to know first

Related concepts

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.