Usually check and set / clear the flag, for example:
if (some_test) { flag |= SOME_FLAG; } else { flag &= ~SOME_FLAG; }
I have found a convenient way around this so far ...
flag = (some_test) ? (flag | SOME_FLAG) : (flag & ~SOME_FLAG);
This can be done in a macro and its OK, but is there some tweedling magic to avoid referencing the flag twice?
(in case multiple instances of flag lead to overhead).
An example of what I'm looking for (if C can perform ternary operations with operators) ...
flag ((some_test) ? (|=) : (&= ~) SOME_FLAG;
The above example is intended only to describe what I am looking for, of course, it will not work in its current form.
source share