-5

I was going through the source code of Intel's deep learning framework Caffe, when I came across |=. I've never seen that before in any code. In fact, I found it twice in the code. Line 188:

need_backward |= blob_need_backward_[blob_id];

and line 254:

need_backward |= param_need_backward;

I realize that they both are housed in a for loop which might signify some kind of relation. I'm just assuming.

Rohitus
  • 159
  • 2
  • 7
  • 6
    I'm voting to close this question as off-topic because this is a question about adequately documented basic syntax. – J... Dec 02 '16 at 02:47
  • 1
    [Scroll down here](https://www.tutorialspoint.com/cplusplus/cpp_operators.htm) "bitwise inclusive OR and assignment operator" – Jhecht Dec 02 '16 at 02:47
  • `|` is a bitwise OR operator. `X op= Y` is a shorthand for `X = X op Y`. Thus, `|=` performs bitwise OR of the two arguments and assigns the result to the first one. – Amadan Dec 02 '16 at 02:47
  • I also don't want to discourage you, or actually: I want to -- I wonder whether you should start with something simpler. – Peter - Reinstate Monica Dec 02 '16 at 03:02

3 Answers3

3

Thats the 'bitwise OR assignment' compund assignment operator.

x |= y;

is equivalent to:

x = x | y;

There are a number of similar operators: +=, -=, *=, etc.

See: operator_assignment

harmic
  • 28,606
  • 5
  • 67
  • 91
2

|= is a compound assignment.

<var> |= <expr> means <var> = <var> | <expr>

It is the bitwise OR equivalent of += for incrementing. You can do this with most mathematical operators in C++.

| is bitwise OR, so you're reassigning a variable to its OR'd result.

Community
  • 1
  • 1
Nate Gardner
  • 1,577
  • 1
  • 16
  • 37
1

it is shorthand for

need_backward = need_backward | param_need_backward;

you are performing bitwise or operation