Re: [fpc-devel] Evaluation order in expressions
On 30.07.2019 09:46, Michael Van Canneyt wrote: I think they updated the documentation meanwhile: http://docwiki.embarcadero.com/RADStudio/Rio/en/Procedures_and_Functions_(Delphi)#Calling_Conventions So you can see it depends on the calling convention. Thanks, I wasn't aware of it! Ondrej ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] Evaluation order in expressions
On Tue, 30 Jul 2019, Ondrej Pokorny wrote: On 30.07.2019 08:55, Jonas Maebe wrote: Delphi evaluates e.g. all parameters to subroutine calls from left to right, which FPC does not guarantee. If I am not mistaken Delphi doesn't guarantee this either. I remember I "learned it by doing" quite some time ago and I don't think I used FPC at that point, so it must have been Delphi. A quick Google search revealed https://stackoverflow.com/a/11010685 - yes, when I run the code from the answer in Delphi 32bit the right "SideEffect(2)" call is executed before the left "SideEffect(1)" call. I think they updated the documentation meanwhile: http://docwiki.embarcadero.com/RADStudio/Rio/en/Procedures_and_Functions_(Delphi)#Calling_Conventions So you can see it depends on the calling convention. Michael. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] Evaluation order in expressions
On 30.07.2019 08:55, Jonas Maebe wrote: Delphi evaluates e.g. all parameters to subroutine calls from left to right, which FPC does not guarantee. If I am not mistaken Delphi doesn't guarantee this either. I remember I "learned it by doing" quite some time ago and I don't think I used FPC at that point, so it must have been Delphi. A quick Google search revealed https://stackoverflow.com/a/11010685 - yes, when I run the code from the answer in Delphi 32bit the right "SideEffect(2)" call is executed before the left "SideEffect(1)" call. Ondrej ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] Evaluation order in expressions
On 2019-07-30 08:23, Ondrej Pokorny wrote: 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? Only if short circuit boolean evaluation is off. (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._") Delphi evaluates e.g. all parameters to subroutine calls from left to right, which FPC does not guarantee. Jonas ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] Evaluation order in expressions
On Tue, 30 Jul 2019, Ondrej Pokorny wrote: On 30.07.2019 08:33, Michael Van Canneyt wrote: The documentation has already been fixed in this regard, there was a bugreport about it not so long ago. Great, thank you. Is there some online version of the latest documentation trunk (nightly build)? No, there is not... Michael. ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] Evaluation order in expressions
On 30.07.2019 08:33, Michael Van Canneyt wrote: The documentation has already been fixed in this regard, there was a bugreport about it not so long ago. Great, thank you. Is there some online version of the latest documentation trunk (nightly build)? Ondrej ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] Evaluation order in expressions
On Tue, 30 Jul 2019, Ondrej Pokorny wrote: On 30.07.2019 08:23, Ondrej Pokorny wrote: /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); A moment of relief. The FPC compiler itself depends on the left-to-right evaluation. E.g. compiler/aoptbase.pas, line 284: while assigned(p1) and assigned(p2) and GetNextInstruction(p1,p1) and (p1<>p2) do So is the documentation wrong or are the compiler (and also my own) sources flawed? The documentation has already been fixed in this regard, there was a bugreport about it not so long ago. Michael.___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Re: [fpc-devel] Evaluation order in expressions
On 30.07.2019 08:23, Ondrej Pokorny wrote: /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); A moment of relief. The FPC compiler itself depends on the left-to-right evaluation. E.g. compiler/aoptbase.pas, line 284: while assigned(p1) and assigned(p2) and GetNextInstruction(p1,p1) and (p1<>p2) do So is the documentation wrong or are the compiler (and also my own) sources flawed? Best Ondrej ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
[fpc-devel] Evaluation order in expressions
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-11.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 ___ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel