liveBook · Manning

Incompatible types

As explained in Modern C

Incompatible types are C types that are not permitted to denote the same compatible type for a particular language construct.

A _Generic expression selects one expression by the type of its controlling expression. Its listed type expressions must be mutually incompatible, so the compiler can choose exactly one match. TAKEAWAY: incompatible types are C types that cannot denote the same compatible type for this construct. section 16.6

Selecting a type-specific function

The fabs macro associates float with fabsf and long double with fabsl, leaving fabs as the default. These associations illustrate distinct type cases in a type-generic interface.

Keep these related constraints in view:

  • Require an unambiguous compile-time choice among the type expressions. section 16.6
  • Reject a pointer to a variable-length array as a _Generic type expression. section 16.6
  • Keep every choice expression valid, including alternatives that are not selected. section 16.6

How Modern C covers it

How deep it goes
Defines mutual incompatibility, forbids pointer-to-VLA associations, and emphasizes validity of every choice expression.
Examples
Demonstrates fabs dispatch and an invalid TRACE_CONVERT alternative involving integer-to-pointer assignment.
What you can do after
Diagnose _Generic macros by checking type compatibility, ambiguity, forbidden pointer-to-VLA associations, and all alternative expressions.
How it connects
Connects _Generic expressions, type-generic programming, compatible types, and pointers to variable-length arrays.

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.