$B+ evaluates RIGHT to LEFT? 
Author Message
 $B+ evaluates RIGHT to LEFT?

Quote:
>The following code (only 5 lines) is written in Borland Pascal 7.0:
>{$B+}
>Function A : Boolean; Begin Write('A'); A := True End;
>Function B : Boolean; Begin Write('B'); B := True End;
>Function C : Boolean; Begin Write('C'); C := True End;
>Begin If A And B And C Then WriteLn End.
>The program writes: CBA
>If the first line is changed to {$B-}, the program outputs: ABC
>Can someone explain why?

The only way you can be sure of the order that these elements are  
processed
is to use parathesis.  By altering the boolean short-circuit switch {$B},  
your
just changing the approach the software uses to evaluate the expression,  
still
no guarentee that the evaluation will _always_ be left to right or right  
to left.


Sat, 17 Apr 1999 03:00:00 GMT  
 $B+ evaluates RIGHT to LEFT?

The following code (only 5 lines) is written in Borland Pascal 7.0:

{$B+}
Function A : Boolean; Begin Write('A'); A := True End;
Function B : Boolean; Begin Write('B'); B := True End;
Function C : Boolean; Begin Write('C'); C := True End;
Begin If A And B And C Then WriteLn End.

Quote:
The program writes: CBA

If the first line is changed to {$B-}, the program outputs: ABC

Can someone explain why?



Sat, 17 Apr 1999 03:00:00 GMT  
 $B+ evaluates RIGHT to LEFT?

Quote:

> The following code (only 5 lines) is written in Borland Pascal 7.0:

> {$B+}
> Function A : Boolean; Begin Write('A'); A := True End;
> Function B : Boolean; Begin Write('B'); B := True End;
> Function C : Boolean; Begin Write('C'); C := True End;
> Begin If A And B And C Then WriteLn End.

> The program writes: CBA
> If the first line is changed to {$B-}, the program outputs: ABC

> Can someone explain why?

Really, very interesting. I think on the same level of priority the compiler
uses recursion instead of loop. In any case, such important things *must* be
documented.

- Hovik Melikian



Sat, 17 Apr 1999 03:00:00 GMT  
 $B+ evaluates RIGHT to LEFT?

Quote:

> Subject: $B+ evaluates RIGHT to LEFT?
> The following code (only 5 lines) is written in Borland Pascal 7.0:
> {$B+}
> Function A : Boolean; Begin Write('A'); A := True End;
> Function B : Boolean; Begin Write('B'); B := True End;
> Function C : Boolean; Begin Write('C'); C := True End;
> Begin If A And B And C Then WriteLn End.
> The program writes: CBA
> If the first line is changed to {$B-}, the program outputs: ABC
> Can someone explain why?

Answer:

Compiler switch $B+ means the compiler will translate your code in that way that
all boolean expressions are checked and in the case of functions are executed.
Program will do it even when next boolean expressions can not change the total
result.
Example:
IF odd (3) OR odd (4) THEN writeln;
Program will check both expressions even odd (4) can not change the result.

Is the compiler switch set to $B- code is translated to interrupt in a case of
next boolean expression can not change the result.
Example:
IF odd (3) OR odd (4) THEN writeln;
Program will just check odd (3), because odd (4) can not change result and then
continue directly with writeln.

So in your example compiler will translate in case of $B- to a code which will
check boolean expression from A to B to C. In case of $B+ compiler checks from
last to first expression C->B->A.
Why? Ask Borland!

Armin Kuebelbeck



Sun, 18 Apr 1999 03:00:00 GMT  
 $B+ evaluates RIGHT to LEFT?

Quote:

> >The following code (only 5 lines) is written in Borland Pascal 7.0:

> >{$B+}...
> >Begin If A And B And C Then WriteLn End.
> >The program writes: CBA
> >If the first line is changed to {$B-}, the program outputs: ABC...
> The only way you can be sure of the order that these elements are
> processed is to use parathesis.  By altering the boolean short-circuit True,
> switch {$B},your just changing the approach the software uses to
> evaluate the expression, still no guarentee that the evaluation will
> _always_ be left to right or right to left.False. ;)

The documentation for Borland (and Turbo) pascal states that with $B-
evaluation is _always_ from left to rigth. AS far as I remember, it also
states that the order of evaluation is not guaranteed with $B+ (barring
brackets, af course), but that all parts of the test will be evaluated.
See programmers reference.

Regards,

Remco
--------------------------------------------------------------------------------
This is an automatically generated signature for Remco Vietor in
netscape.
The views expressed in this message should be taken as the personal views
of
the author, unless stated otherwise.



Fri, 23 Apr 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. + evaluates RIGHT to LEFT?

2. + evaluates RIGHT to LEFT

3. detecting shift (left right up dn pgup pgdn home end)

4. language right to left problems

5. Report with data flow from left to right

6. UP - DOWN - LEFT - RIGHT (HELP)

7. Report with data flow from left to right

8. Needed: Component to handle currencies while digits appear right-to-left

9. LEFT JOIN: Wrong results when left table is empty

10. BS/1 Source Code

11. B.S. Delphi SQL Error?

12. Help me evaluate this web database recommendation

 

 
Powered by phpBB® Forum Software