#define FLAG_FAILED:1
is not really a bit flag in the sense that what most people know as a "bit flag". It's also bad syntax.
Bit flags typically are defined so that you have a type and you turn "on" bits by "setting" them. You turn them "off" by "clearing" the flag. To compare if the bit flag is on, you use what is called the bitwise operator AND
(e.g. &).
So your BIT0 (e.g. 2^0) would be defined as BIT0 = 0x00000001
and BIT1 (e.g. 2^1) as BIT1 = 0x00000002
. If you wanted to stick with define you could do it this way with setting and clearing:
#ifndef setBit
#define setBit(word, mask) word |= mask
#endif
#ifndef clrBit
#define clrBit(word, mask) word &= ~mask
#endif
or as a template
template<typename T>
inline T& setBit(T& word, T mask) { return word |= mask; }
template<typename T>
inline T& clrBit(T& word, T mask) { return word &= ~mask; }
If you want to set the bit, so to speak, you could have a state set as follows:
setBit(SystemState, SYSTEM_ONLINE);
or
setBit(SystemState, <insert type here>SYSTEM_ONLINE);
clearing would be the same just replace setBit
with clrBit
.
To compare, just do this:
if (SystemState & SYSTEM_ONLINE) { ... // do some processing
}
if this is in a struct
then, reference the struct
.