Arithmetic and Slice Conversions
Explore arithmetic and slice conversions in D programming, focusing on type promotion rules for safe arithmetic operations and the automatic conversion of fixed-length arrays to slices. Understand potential bugs with signed and unsigned types and how improper slice usage can lead to undefined behavior.
We'll cover the following...
Arithmetic conversions
There are other conversion rules that are applied for arithmetic operations. In general, automatic arithmetic conversions are applied in the safe direction: from the narrower type to the wider type. Although this rule is easy to remember and is correct in most cases, automatic conversion rules are very complicated, and in the case of signed-to-unsigned conversions, carry some risk of bugs.
The arithmetic conversion rules are the following:
-
If one of the values is
real, then the other value is converted to ...