What you are actually testing is the "order of evaluation of parameters",
something which your code (a function with side effects, since you modify
the parameter) should never rely on.

A simpler example (using a global instead of a var parameter, which amounts
to the same thing) would be:

  function NextParameter: word;
  begin
    Inc(I);
    Result := I;
   end;
   ...
   I := 0;
   Test(NextParameter, NextParameter, NextParameter);

which will also produce 3 2 1 (without any of the messy pointer stuff )

Expressions are associative left to right[*], meaning that (using D2007, at
least):
   I := 0;
   J := (NextParameter * 100) + (NextParameter * 10) + NextParameter;
   writeln(j);
will produce 123 (i.e. "functions are executed from left to right" in this
specific case).

[*] - function calls within expression may NOT be evaluated left to right,
even though the final expression is associative left to right. Depending on
the parameter types and complexity of the expression, a compiler MAY use
some other evaluation order in the interest of optimum code generation, for
example, if it is necessary to stack operand results along the way. In this
case the functions may be evaluated right to left so that they can be taken
from the stack in reverse order (left to right) to evaluate the expression.

If the order of evaluation of functions is important (as is normally the
case for functions with side effects), you need to write your code to
enforce the required order.

Regards,
Ken


__________________________________________________
Delphi-Talk mailing list -> Delphi-Talk@elists.org
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to