* * *

Author Topic: Boolean evaluation  (Read 4359 times)

typo

  • Hero Member
  • *****
  • Posts: 3051
Boolean evaluation
« on: April 19, 2010, 05:48:12 pm »
How is the FPC standard boolean evaluation, complete? Anyone knows?

The $B directive switches between the two different models of Delphi code generation for the and and or Boolean operators.

In the {$B+} state, the compiler generates code for complete Boolean expression evaluation. This means that every operand of a Boolean expression built from the and and or operators is guaranteed to be evaluated, even when the result of the entire expression is already known.

In the {$B-} state, the compiler generates code for short-circuit Boolean expression evaluation, which means that evaluation stops as soon as the result of the entire expression becomes evident in left to right order of evaluation.
« Last Edit: April 19, 2010, 06:07:21 pm by typo »

Zoran

  • Hero Member
  • *****
  • Posts: 1148
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Boolean evaluation
« Reply #1 on: April 19, 2010, 07:38:23 pm »
Making simple test gives the answer, I just tried:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
  if (MessageDlg('1', mtConfirmation, [mbYes, mbNo], 0) = mrYes)
       and (MessageDlg('2', mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
    ShowMessage('yes, yes');

end;

If your first answer is no, you are not asked for second time. Try it.

Only if you put {$B+} above the procedure, you are asked the second time, regardless of your first answer.

So, the default is short-curcuit.
« Last Edit: April 19, 2010, 07:40:37 pm by Zoran »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Boolean evaluation
« Reply #2 on: April 19, 2010, 08:07:30 pm »
Thanks.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus