[fpc-devel] Problem with {$BOOLEVAL ON/OFF} and it's default.

Skybuck Flying skybuck2000 at hotmail.com
Wed Jun 15 01:58:05 CEST 2011


Solved:

The solution required one little line fixed:

{ifopt b+}

Anyway I have improved the test program somewhat, because it was a bit shitty, it's still a little bit shitty but not as shitty ! ;) =D

// *** Begin of Test Program ***

program TestProgram;

{$APPTYPE CONSOLE}

{

Test complete boolean evaluation compiler switches to see if they
are unit/file width or per routine or per code section

version 0.01 created on 14 june 2011 and fixed/improved on 15 june 2011 by Skybuck Flying

Conclusion: it works per code section however there is a potential problem:

It might not be possible to return to the "default settings" ?!?

For example once B+ is done all code below it will be effected ?!?
B- might then turn it off... but what if project default was on ?!?

Perhaps it can be solved with $if or so... and some kind of storage...

It's fucked up/abortion-ed ;) I don't think it's possible so for now
I will have to stick with B+ down below the code sections ;)

Ok solved,

Solution is to use:

  $ifopt b+

Thanks to "Bart" on usenet for providing this solution, he usefull after all ! ;) =D

}

uses
  SysUtils;

function Function1 : boolean;
begin
writeln('function1 called, result: true');
result := true;
end;

function Function2 : boolean;
begin
writeln('function2 called, result: false');
result := false;
end;

function Function3 : boolean;
begin
writeln('function3 called, result: true');
result := false;
end;

// default result: function3 not called, pretty bad.
procedure TestRoutine1;
var
vResult : boolean;
begin
writeln('TestRoutine1 - DEFAULT - BEGIN');
vResult := true;
vResult := vResult and Function1;
vResult := vResult and Function2;
vResult := vResult and Function3;
writeln('TestRoutine1 vResult: ', vResult );
writeln('TestRoutine1 - DEFAULT - END');
writeln;
end;

procedure TestRoutine2;
var
vResult : boolean;
begin

{$ifopt b+}
  {$define CompleteBooleanEvaluationWasOn }
  writeln('Default for Complete Boolean Evaluation is On.');
{$else}
  {$define CompleteBooleanEvaluationWasOff}
  writeln('Default for Complete Boolean Evaluation is Off.');
{$endif}
writeln;

{$BOOLEVAL ON}
writeln('TestRoutine2 - BOOLEVAL ON - BEGIN');
vResult := true;
vResult := vResult and Function1;
vResult := vResult and Function2;
vResult := vResult and Function3;
writeln('TestRoutine2 vResult: ', vResult );
writeln('TestRoutine2 - BOOLEVAL OFF - END');
writeln;
{$BOOLEVAL OFF}

writeln('TestRoutine2 - CONTINUATION - BEGIN');
vResult := true;
vResult := vResult and Function1;
vResult := vResult and Function2; // off works... so it's code specific ok nice. however what will happen outside of code... will it go to default ?!?
vResult := vResult and Function3;
writeln('TestRoutine2 vResult: ', vResult );
writeln('TestRoutine2 - CONTINUATION - END');
writeln;

{$if Defined(CompleteBooleanEvaluationWasOn)}
  writeln('Falling back to Default Complete Boolean Evaluation which was On.');
  {$BOOLEVAL ON}
{$ifend}

{$if Defined(CompleteBooleanEvaluationWasOff)}
  writeln('Falling back to Default Complete Boolean Evaluation which was Off.');
  {$BOOLEVAL OFF}
{$ifend}
writeln;

writeln('TestRoutine2 - BOOLEVAL DEFAULT');
vResult := true;
vResult := vResult and Function1;
vResult := vResult and Function2; // off works... so it's code specific ok nice. however what will happen outside of code... will it go to default ?!?
vResult := vResult and Function3;
writeln('TestRoutine2 vResult: ', vResult );
writeln('TestRoutine2 - BOOLEVAL DEFAULT');
writeln;

end;

// little problem... booleval remains on... and now we don't know what the default behaviour was ?!?
// it's desireable to fall back to default behaviour for the rest of the code ?!?
// problem solved.
procedure TestRoutine3;
var
vResult : boolean;
begin
writeln('TestRoutine3 - OUTSIDE - BEGIN');
vResult := true;
vResult := vResult and Function1;
vResult := vResult and Function2;
vResult := vResult and Function3;
writeln('TestRoutine3 vResult: ', vResult );
writeln('TestRoutine3 - OUTSIDE - END');
writeln;
end;


procedure Main;
begin
writeln('program started');

TestRoutine1;
TestRoutine2;
TestRoutine3;

writeln('program finished');
end;


begin
  try
Main;
  except
on E: Exception do
   Writeln(E.ClassName, ': ', E.Message);
  end;
  ReadLn;
end.

// *** End of Test Program ***

Bye,
  Skybuck.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20110615/620384e7/attachment.html>


More information about the fpc-devel mailing list