I like "set" / "clear", but be careful of ambiguity in your phrasing. As Filip points out, "set the bool variable" could be taken to mean writing some value to the variable. But "setting the flag" is more clear.
Related terminology: turning a 0 / non-zero integer into a 0 / 1 value is called "booleanizing".
If you actually use the 0 / 1 value as an integer (instead of as a true/false bool
), you may want to use that word. Otherwise it will probably only come up if you're talking about the cost of the operations the compiler has to perform. (Or if you're manually vectorizing with a SIMD compare to produce all-zero / all-one bits in each vector element).
In C and C++, a bool
can implicitly convert back into an integer as 0 or 1, and on normal implementations bool
is stored as a one-byte value that is either 0 or 1 (not just any non-zero value). The allows efficient a && b
, but in practice many C compilers have missed optimizations.
bool booleanize(int a) { return a; } // C++
That function compiles to multiple instructions (not including the ret
) on most architectures. (MIPS being an interesting exception, having compare-into-register instructions instead of a separate flag / condition-code register). on the Godbolt compiler explorer for x86-64, MIPS, and ARM thumb, we can see the x86-64 version is:
test edi, edi # set flags according to a & a
setne al
ret # return value in AL, the low byte of RAX
Sorry this example of what booleanizing is got a little large / off-topic!