I have encountered code like
if (flagsDef)
flagsTainted |= flagsUsed;
please assist in knowing the meaning of the operator used.
I have encountered code like
if (flagsDef)
flagsTainted |= flagsUsed;
please assist in knowing the meaning of the operator used.
The statement:
is shorthand for:
which uses the binary/bitwise OR operator
|
.The code is manipulating a flag variable, which is keeping state information by setting bits in the variable
flagsTainted
.For more information about bitwise manipulation, the wikipedia article is pretty good.
|
is a bitwise OR. This means that it compares the bits using an or operator.For example:
If you
|
the two, you get 101. The | = assigns the result back to the left hand side of the operation.It can be read in English as "or equals".
It's similar to += except instead of adding the left value to the right, it instead performs a bitwise or of the two values and then assigns the result into the left variable as you would expect.
For more information on bitwise operations, see this link: Wikipedia
a op= b
isa = a op b
, and|
is the bitwiseor
operator (bitwise meaning it's applied for each binary digit).Here is the truth table for
or
: