Contents | Prev | Next | Index
The type of an expression can be changed to another type through a typecast. The syntax of a typecast looks like a function call with exactly one actual parameter. However, the function identifier is replaced with a type identifier. There are two kind of typecasts: Value typecasts and variable typecasts.
factor ::= primary |
expr_designator ::= designator ::= func_var_ref func_var_ref ::= func_result selector_list func_result ::= proc_designator actual_parameters proc_designator ::= expr_designator |
A variable typecast changes the variable expression designator of one type into a variable expression designator of another type. The programmer is responsible for determining the validity of a typecast. The variable expression is treated as an instance of the type specified by the type identifier. The old and new types must be of the same size. If typecasting involves structured types such as records, arrays, set types, or file types, or if it involves pointers, then typecasting in this compiler becomes subject to Java's typecast runtime checking. Typecasting pointer variables is usually not possible in many cases with this compiler because of Java restrictions. A variable typecast is followed by selectors such as index, field, or pointer dereference in order to denote an expression designator. This designator can also be used on the left side of an assignment. It can also be used on the right side of an assignment, and this possibly as part of a more complex expression.
A value typecast operates on expressions and is grammatically the same as a function call with exactly one actual value parameter. It converts the ordinal type of the actual parameter expression into another ordinal type expression. The conversion may involve truncation or extension of the original value if the new and old types are of different sizes. In case where the value is extended it preserves the sign for signed integers through sign extension. A value typecast may not be followed by a selector list. It is regarded as a primary, which is a factor, which in turn is part of an expression.
Notice that the terms variable typecast and value typecast have slightly different meanings in Canterbury Pascal and Borland Object Pascal. The latter uses the term variable typecast also in cases where it is not followed by a selector list for referencing variables.
Typecasting is highly platform dependent and should be regarded as a low level feature only. Because Canterbury Pascal always maps records to Java classes, it is not possible to use record typecasting in order to re-interpret the record memory as having a different layout.
Contents | Prev | Next | Index
Canterbury Pascal for JVM (Last documentation update
Sep 02, 2004)
Copyright © 1999-2004 J.Neuhoff - mhccorp.com
. All rights reserved.
Please send any comments or corrections to
neuhoff@mhccorp.com