Hi Bill,
What would a function prototype look like that takes one parameter but
several options can be OR'd together in that parameter? For example:
function(LEFT|RIGHT);
What would the parameter source code look like?
Usually, this is an integer (of some size) data type.
The manifest constants LEFT and RIGHT are typically disjoint
bitsets (though they need not be). They can also be derived
from an enumerated type, etc.
E.g., render_text(const char *string, attr_t attributes)
where:
attributes ::= BLINK | BOLD | DIM | INVISIBLE | ITALIC | etc.
(note my use of '|' here is in the context of a BNF, not a
C statement; also, this specfication says nothing about how
"sensible" BLINK | INVISIBLE might be! :> )
So,
render_text("Big SALE today!!", BOLD | BLINK);
one of the semantic problems with the use of "or" is that it
really is implementing what you would COLLOQUIALLY think of
as an "and" function: "Make this BOLD *and* BLINKing".
Unfortunately, using '+' as a more intuitive conjunctive
opens the door for all sorts of "hidden" errors. E.g.,
BLINK + BLINK might == BOLD, by coincidence. Or, overlapping
bit patterns can cause other unexpected results. For example,
BLINK + INVISIBLE == ITALIC (because the developer assumed
"BLINK + INVISIBLE" was meaningless -- "/* CAN'T HAPPEN */ -- and
chose the ITALIC bit pattern to coincide with this value,
by chance.
Of course, there are other perils with building values out
of bit masks but that's another story...