Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
does ZB have a compile-time operator, for constants, for left/right shift?
like
(1<<constant1) OR (1<<constant2)
versus
shl(1, constant1) OR shl(1, constant2)
shl() is run-time, I suppose, unless the compiler's optimizer converts the above to a compile-time constant rather than using run time function calls despite the constants
stevech wrote:does ZB have a compile-time operator, for constants, for left/right shift?
For many functions, including Shl and Shr, if the parameters are constant the compiler computes the result at compile-time. This can be seen, for example, by compiling this code:
I should have remarked that the same compile-time computation applies to expressions with constant operands, too, so your example of shl(1, constant1) OR shl(1, constant2) will evaluate to a constant at compile-time.
stevech wrote:I assume that applies as well where the storage is an I/O register.
Yes. The use to which an expression's value is put is immaterial - the compiler will optimize an expression as much as it can, possibly reducing it to a constant value.