Previous: , Up: Expressions   [Contents][Index]

4.17.10 Type Casting

When two operands on each side of a binary expression have different type, mailfromd evaluator coerces them to a common type. This is known as implicit type casting. The rules for implicit type casting are:

  1. Both arguments to an arithmetical operation are cast to numeric type.
  2. Both arguments to the concatenation operation are cast to string.
  3. Both arguments to ‘match’ or ‘fnmatch’ function are cast to string.
  4. The argument of the unary negation (arithmetical or boolean) is cast to numeric.
  5. Otherwise the right-hand side argument is cast to the type of the left-hand side argument.

The construct for explicit type cast is:


where type is the name of the type to coerce expr to. For example:

string(2 + 4*8) ⇒ "34"

A special case of type casting is cast to void. It is used to ignore return value of a function call between the braces, e.g.:

void(dlcall(libh, "extlog", "s", text))