Narrowing conversion
A narrowing conversion converts a value to a type with a smaller representable range or lower precision, potentially losing information.
100 Java Mistakes and How to Avoid Them
A narrowing conversion converts a value to a type with a smaller representable range or less general numeric domain, potentially discarding information.
- How it is used
- Explains how Java casts and compound assignments can discard numeric information and cause incorrect program behavior.
- How deep it goes
- Works through overflow, bit loss, widening order, and analyzer limits, then stops short of a general numeric-conversion taxonomy.
- Examples
- Uses file lengths, character multiplication, negative bytes, and unsigned right shifts as concrete failure cases.
- What you can do after
- Diagnose unsafe casts and compound assignments, then replace them with range checks, exact conversion, or wider types.
Read how 100 Java Mistakes and How to Avoid Them explains narrowing conversion →
Modern C
A narrowing conversion is a conversion to a type whose representable range or precision cannot preserve all values of the source type.
- How it is used
- Warns against value loss in assignments and mixed-type arithmetic.
- How deep it goes
- Explains fitting values, overflow-related results, precision loss, and mixed signedness, but defers broader type-rule details.
- Examples
- Uses integer assignments, floating-point expressions, and signed-versus-unsigned comparisons to expose harmless and dangerous conversions.
- What you can do after
- Evaluate C conversions for representability, information loss, precision loss, and mixed signedness.
Modern C, Third Edition
A narrowing conversion is a conversion to a type that represents a smaller range or less precise set of values than the source type.
- How it is used
- Uses implicit conversions to evaluate whether assignments and mixed-type operations preserve values safely.
- How deep it goes
- Explains value-fit checks, literal-specific behavior, unsigned modular conversion, and precision loss in mixed arithmetic.
- Examples
- Uses signed and unsigned assignments, hexadecimal and decimal minimum values, and mixed integer-floating-point expressions.
- What you can do after
- Evaluate whether conversions preserve values and identify cases that may lose range, precision, or information.
Read how Modern C, Third Edition explains narrowing conversion →
Related concepts
- implicit conversionkind of · Implicit conversion is an automatic change of a value from one type to another according to language rules, without an explicit conversion operation in the source code.
- augmented assignmentused by · Augmented assignment is syntax that combines an operation with assignment to update a variable or object using its current value.
- uniform initializationcontrasts with · Uniform initialization is C++ syntax that uses braces to initialize objects and values.
- data conversionimplemented by · Data conversion is the transformation of a value or data from one type, format, or representation to another, explicitly or implicitly.
- numerical overflowproduces · Numerical overflow is the condition in which an arithmetic result falls outside the range representable by its numeric type or format.
- widening conversioncontrasts with · A widening conversion converts a value to a type with a broader representable range or compatible numeric domain without requiring an explicit cast or conversion operation.
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.


