Additional SemanticsΒΆ

Casts

A _cast statement changes the type of an expression or an l-lvalue to a given type. Beware that the type-checker is forced to accept the new type as is, and must trust the programmer about the new semantics of the expression/l-value. Bad casts can raise errors in the next stages of the back-end, or even lead to invalid output code.

Casts work both on expressions and l-values. For instance, these are valid casts:

_cast("a", int)


_cast(a_string, int) := 42

Warning

These examples could produce code with a strange behavior at execution time.

Casts are currently only used in concrete syntax transformations inside the bounds checking extension and, as any language extension, are forbidden in standard Tiger programs.