Page 1 of 1

Use const() for booleans?

Posted: Thu Sep 16, 2021 7:52 am
by Pete (NZ)
A newbie Q here (first post!)... :) ...

The docs say...
The argument to const() may be anything which, at compile time, evaluates to an integer e.g. 0x100 or 1 << 8. It can even include other const symbols that have already been defined, e.g. 1 << BIT.
Sure, a boolean can be represented by an integer (-1 | 0), but does the optimization potential of using const() still apply if the value is set to TRUE | FALSE...?

Thanks! :)

Re: Use const() for booleans?

Posted: Sat Sep 25, 2021 1:13 am
by samneggs
I don't know about Boolean optimization but I use them to selectively turn on/off sections of code. So near the top of the code after importing I have the constants DEMO_MODE = const(False) # set True for demo mode or THREADED = const(False) # set True to crash.
Sam