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

Skybuck Flying skybuck2000 at hotmail.com
Tue Jun 14 03:04:40 CEST 2011


Hello,

I want to make sure that complete boolean evaluation for certain code 
sections is on.

However after the code section I want the "complete boolean evaluation" 
compiler switch state back to what it was/the default.

So I would like to write something like:

{$if BOOLEVAL = ON}
    {$define CompleteBooleanEvaluationWasOn}
{$ifend}

{$if BOOLEVAL = OFF}
    {$define CompleteBooleanEvaluationWasOff}
{$ifend}

{$BOOLEVAL ON}
     ... code section ...
{$if CompleteBooleanEvaluationWasOn}
    {BOOLEVAL ON}
{$ifend}

{$if CompleteBooleanEvaluationWasOff}
   {BOOLEVAL OFF}
{$ifend}

So I would like the rest of the code to be un-effected by my compiler switch 
change just to make sure that everything else compiles as normal/default.

However it either doesn't seem to be possible to write it like this or I am 
not good enough at writing conditional compiler directives.

Is it possible to solve it with compiler directives ?

If not then perhaps Delphi Compiler needs a "default" directive like so:

{$BOOLEVAL DEFAULT}

This would take the project options default value for this compiler 
directive to solve the problem ! ;) =D

I haven’t tried yet with Free Pascal, so what you guys think ? Possible or not ?! 
(I’m thinking not... so not even going to try it... but do surprise me if you can !)

To help you try it out here is a test program.
It's a little bit like an abortion... it's a little bit fucked up ! ;) =D
But it's not to bad... if you do know how to solve it... then you can do it ! ;) =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 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...

}

uses
  SysUtils;

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

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

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

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

procedure TestRoutine2;
var
vResult : boolean;
begin

{$BOOLEVAL ON}

{$if (BOOLEVAL = ON)}
  {$define CompleteBooleanEvaluationWasOn }
  writeln('it''s on');
{$else}
  {$define CompleteBooleanEvaluationWasOff}
  writeln('it''s off');
{$ifend}

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

writeln('TestRoutine2 begin2');
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 end2');

{$if Defined(CompleteBooleanEvaluationWasOn)}
  writeln('turning it on');
  {$BOOLEVAL ON}
{$ifend}

{$if Defined(CompleteBooleanEvaluationWasOff)}
  writeln('turning it off');
  {$BOOLEVAL OFF}
{$ifend}

writeln('TestRoutine2 begin3');
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 end3');

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 ?!?
procedure TestRoutine3;
var
vResult : boolean;
begin
writeln('TestRoutine3 begin');
vResult := true;
vResult := vResult and Function1;
vResult := vResult and Function2;
vResult := vResult and Function3;
writeln('TestRoutine3 vResult: ', vResult );
writeln('TestRoutine3 end');
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/20110614/0d909312/attachment.html>


More information about the fpc-devel mailing list