VMS Help PASCAL, Expressions, Operators, Type Cast Operator *Conan The Librarian (sorry for the slow response - running on an old VAX) |
The type cast operator changes the context in which a variable or an expression of a certain data type can be used. The actual representation of the object being cast is not altered by the type cast operator. Compaq Pascal overrides the type only for the duration of one operation. It has one of the following forms: variable-identifier :: type-identifier (expression) :: type-identifier The type cast operator (::) separates the name of the variable or an expression in parentheses from its target type, the type to which it is being cast. Example: TYPE F_Float = PACKED RECORD Frac1 : 0..127; Expo : 0..255; Sign : Boolean; Frac2 : 0..65535; END; VAR A : REAL; {In the executable section:} A :: F_Float.Expo := A :: F_Float.Expo + 1; The record type 'F_Float' illustrates the layout of an F_floating real number. The real variable 'A' is cast as a record of this type, allowing access to the fields containing the mantissa, exponent, sign, and fraction of 'A'. Adding 1 to the field containing the exponent would give the same result as multiplying 'A' by 2.0.
|