next up previous contents
Next: Sequential Control Up: The MPD Programming Language Previous: Type Equivalence   Contents

Subsections

Type Conversions

Sometimes a value of one type can be converted into a value of another type. This can occur implicitly or explicitly. There is only one implicit conversion: from integers to reals.

Implicit Conversion

It is important to understand when the conversion takes place since this may effect the result. Consider the following:

real r = 3, h1, h2
int  i = 10

h1 = i / r
h2 = i / 3

Here, in the second division the integer result of i / 3 will be converted to a real before being assigned to h2, while in the first division
texttti will be converted to a real before being used in the division. Thus, h1 = 3.33333 and h2 = 3.00000.

Explicit Conversion

MPD contains conversion functions for the five basic types, integers, booleans, reals, characters and strings as well as for three user defined sorts of types, enumerations, pointers and arrays of characters.

See appendix C of the SR Book (available from the MPD web page) for a complete list of those functions.



David Sands 2003-09-05