Contents | Prev | Next | Index


Procedural Expressions

Usually, when a procedural variable is used in a statement or expression, the procedure or function stored in that variable is called. There is only one exception: When the compiler sees a procedural variable on the left side of an assignment, it knows that the procedural variable designator is not a function call but rather stands for its procedural value which is about to be reassigned. Otherwise, if the procedural variable identifier is to refer to the value of that variable it always needs to be preceded by the address operator @. Also, if the address of a function is needed, the function identifier has to be preceded by an address operator, too. For example, consider the following program:

TYPE
  IntFunc = FUNCTION : INTEGER;

VAR
  F : IntFunc;
  G : IntFunc;
  N : INTEGER;
  M : INTEGER;

FUNCTION ReadInt : INTEGER;
VAR
  I : INTEGER;
BEGIN
  Read(I);
  ReadInt := I;
END;

BEGIN
  F := @ReadInt; { Assign procedural value }
  G := @F;       { Assign procedural value }
  N := ReadInt;  { Assign function result }
  M := F;        { Assign function result }
END.

The first and second statements in the main program assign the procedural value, that is the address of ReadInt, to the procedural variables F and G, whereas the third and fourth statements call ReadInt and assign the returned value to N and M. The distinction between getting the procedural value or calling the function is made by the preceding address operator @.

Notice that in Borland Object Pascal, as an exception to the above described address operator rule, the address operator does not need to be specified for a right side procedural variable or procedure/function designator if the left side of the assignment is a procedural variable. This is different in Canterbury Pascal where the right side procedural variable or procedure/function designator always has to be preceded by an address operator in order to get its procedure or function pointer value. 


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