home download demos platforms restrictions help

 

What are early out logical AND and OR operators?

The XCSB logical AND and OR operators are early out operators just like the C equivalents. What this means is that while an expression containing these operators is being evaluated (at runtime in the PIC microcontroller) it will be possible at some point to determin if the rest of the expression can be skipped.

The XCSB logical AND operator is && and the logical OR operator is ||

For an expression of the form X AND Y it is possible to skip evaluating Y if X is false. This is because if X is false the value of the overall expression X AND Y will always be false no mater whether Y evaluates to true or false

For an expression of the form X OR Y it is possible to skip evaluating Y if X is true. This is because if X is true the value of the overall expression X OR Y will always be true no mater whether Y evaluates to true or false

Unlike many other BASIC compilers, XCSB will optimise logical expressions to take advantage of early out possibilities.

Early out logical expression are vary useful in C as guard expressions. This means that the first part of the expression protects the second part of the expression from execution if this would cause a problem.

This is simple example showing guarded access to an array element. Here the array element is only looked at if the index is within the bounds of the array

Non-XCSB example

	if j < 0 then 100
	if j > 9 then 100
	if arr[j] != 0 then 100

	rem do something with arr[j]   

100

XCSB equivalent

    if j>=0 && j<=9 && arr[j]==0 then   
        // do something with arr[j]
    endif


 
home download demos platforms restrictions help