liveBook · Manning

Assignment compatibility

Assignment compatibility is a type-system relation determining whether a value or expression of one type can be assigned to an object of another type.

How 3 Manning books explain it

Fabulous Adventures in Data Structures and Algorithms

Assignment compatibility is the C# type-system rule determining whether an expression of one type may be assigned to a variable of another type.

How it is used
Models C# assignments as type relationships and uses them to explain generic variance.
How deep it goes
Defines the relation, works through covariant and contravariant interfaces, and stops short of a broader programming-language analysis.
Examples
Uses Animal, Giraffe, Tiger, IE<T>, and IC<T> to demonstrate ordinary, covariant, and contravariant assignments.
What you can do after
Understand why subtype assignments and generic interface assignments can preserve or reverse type relationships.

Read how Fabulous Adventures in Data Structures and Algorithms explains assignment compatibility →

Building User-Friendly DSLs

A directional type relation in which every value of one type can be assigned as a value of another type.

How it is used
Uses compatibility checks to validate typed attributes and values and to drive type-dependent rendering.
How deep it goes
Defines directional assignability but implements only equality-based compatibility, deferring richer subtype and coercion rules.
Examples
Demonstrates built-in amount, date range, percentage, and untype objects plus attribute-value mismatch reporting.
What you can do after
Diagnose typed attribute mismatches and understand how type-object equality controls validation and number rendering.

Read how Building User-Friendly DSLs explains assignment compatibility →

Modern C

Assignment compatibility is the C property that a value can be assigned to an object of a specified type under the language's permitted conversions.

How it is used
Uses assignment compatibility to validate macro arguments while preserving compiler diagnostics.
How deep it goes
Explains the definition, contrasts casts with assignment, and demonstrates compound-literal checking.
Examples
Demonstrates arithmetic tracing with +0 and pointer tracing with void* casts or compound-literal assignment.
What you can do after
Apply it via C compound literals to make the compiler check whether an expression is assignable to a chosen type.

Read how Modern C explains assignment compatibility →

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.