Search code examples
c++bit-manipulationoperator-precedence

|= (or_eq) order of evaluation in C++


I was trying to find the answer to the following question, but was unsuccessful. I have the expression involving bit AND and bit OR (everything unsigned long):

A |= B & C

What is the order of evaluation in C++? Is it A = A | (B & C) or A = (A | B) & C? Or it depends on the compiler version? Thanks.


Solution

  • With the compound assignment operators (op=), the expression E1 op= E2 becomes E1 = E1 op E21. That means for your code that E1 is A and E2 is B & C so the result would be

    A = A | (B & C)