liveBook · Manning

_Generic

_Generic is a C11 primary expression that selects one expression from type-associated alternatives according to the type of a controlling expression.

How 2 Manning books explain it

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.

Read how Modern C, Third Edition explains _Generic →

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.

Read how Modern C explains _Generic →

Related concepts

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.