_Generic is a C11 primary expression for type-generic programming. It examines the type of a controlling expression, then selects one expression associated with that type or with default. Although it is not itself a macro feature, it fits naturally inside function-like macro interfaces. section 16.6
1 _Generic(controlling expression,
2 type1: expression1,
3 ... ,
4 typeN: expressionN)
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":1}],[{\"line\":1,\"ch\":10},{\"line\":1,\"ch\":11}],[{\"line\":0,\"ch\":4},{\"line\":0,\"ch\":12}],[{\"line\":1,\"ch\":0},{\"line\":1,\"ch\":1}],[{\"line\":2,\"ch\":0},{\"line\":2,\"ch\":1}],[{\"line\":3,\"ch\":0},{\"line\":3,\"ch\":1}]]"}
!@%STYLE%@!
The form lists a controlling expression followed by type-to-expression associations; one association may use default. section 16.6
Selecting a type-specific function
A type-generic fabs interface can select fabsf for float, fabsl for long double, and fabs otherwise: #define fabs(X) \ _Generic((X), \ float: fabsf, \ long double: fabsl, \ default: fabs)(X) The selected expression is a function pointer. The following (X) applies that function to the argument. Other arithmetic types, including double and integer types, use the default association. section 16.6
Combining argument types
A floating-point minimum interface defines min, minl, and minf, then uses _Generic((A)+(B), ...) to select among them. Using the sum as the controlling expression lets the usual arithmetic conversions determine the relevant combination of the two argument types; the selected function is then called with (A), (B). section 16.6
TAKEAWAY: _Generic chooses by type, not by a runtime value. This makes it useful for presenting a simple macro interface while dispatching to different functions or expressions. More elaborate interfaces can also use it to choose format strings or conversions for tracing. section 16.6

