Search code examples
booleanflags

Why are bools are sometimes referred to as "flags"?


Why are bools sometimes referred to as "flags"? Is it just a metaphor or is there some historical reason behind it?


Solution

  • Flags are an ancient way to convey information. A flag, if we ignore lowering it to half-mast, has only two states - raised or not raised. E.g., consider a white flag - raising it means surrendering. Not raising it, the default state, means that you are not surrendering.

    A boolean variable, like a flag, only has two states - true and false.