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-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.

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 →

What to know first

Related concepts

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.