[fpc-devel] Evaluation order in expressions

Ondrej Pokorny lazarus at kluug.net
Tue Jul 30 08:23:11 CEST 2019


Hello,

can somebody comment on the Remark from 
https://www.freepascal.org/docs-html/ref/refch12.html ?
/Remark: The order in which expressions of the same precedence are 
evaluated is not guaranteed to be left-to-right./

Is this valid for boolean expressions, too? I use the following 
construct with {$BOOLEVAL OFF}:
Result := Assigned(MyObject) and (MyObject.Value>5);
The remark above suggests that I cannot use it because 
(MyObject.Value>5) may be evaluated before Assigned(MyObject) if the 
optimizer decides so.

On the other hand, the information in 
https://www.freepascal.org/docs-html/current/prog/progsu4.html#x11-100001.2.4 
suggests the opposite:
/So, in the following example, the function Bofu, which has a boolean 
result, will never get called.//
//If False and Bofu then/

Delphi documentation also explicitly states that the expressions are 
evaluated in left to right order: 
http://docwiki.embarcadero.com/RADStudio/Rio/en/Boolean_short-circuit_evaluation_(Delphi_compiler_directive)

(Well it is no surprise because 
https://www.freepascal.org/docs-html/ref/refch12.html states that "/This 
behaviour is distinctly different from Delphi or Turbo Pascal./")

Ondrej

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190730/2bedec79/attachment.html>


More information about the fpc-devel mailing list