Explicit Type Conversion
Most languages provide some capability for doing explicit conversions, both widening and narrowing. In some cases, warning messages are produced when
an explicit narrowing conversion results in a significant change to the value of the object being converted.
In the C-based languages, explicit type conversions are called casts. To specify a cast, the desired type is placed in parentheses just before the expression to be converted, as in
One of the reasons for the parentheses around the type name in these conversions is that the first of these languages, C, has several two-word type names, such as long int.
In ML and F#, the casts have the syntax of function calls. For example, in F# we could have the following:
Errors in Expressions
A number of errors can occur during expression evaluation. If the language requires type checking, either static or dynamic, then operand type errors cannot occur. The errors that can occur because of coercions of operands in expressions have already been discussed. The other kinds of errors are due to the limitations of computer arithmetic and the inherent limitations of arithmetic.
The most common error occurs when the result of an operation cannot be represented in the memory cell where it must be stored. This is called overflow or underflow, depending on whether the result was too large or too small. One limitation of arithmetic is that division by zero is disallowed. Of course, the fact that it is not mathematically allowed does not prevent a program from attempting to do it.
Floating-point overflow, underflow, and division by zero are examples of run-time errors, which are sometimes called exceptions.