What does |= mean?

Feb 26, 2015 at 10:16pm
I saw |= used in an example for creating a vertex shader.

1
2
3
#if defined( DEBUG ) || defined( _DEBUG )
     shaderFlags |= D3DCOMPILE_DEBUG;
#endif 
Feb 26, 2015 at 11:12pm
Just a shorter way of writing the following:
1
2
 
  shaderFlags = shaderFlags | D3DCOMPILE_DEBUG;

Feb 26, 2015 at 11:14pm
Its an operator called Bitwise OR assignment. Not sure what it does though, try googling that.
Feb 27, 2015 at 12:49am
In that case it means you're adding the debug flag to the list of flags you have already, it does something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
unsigned char current flag = 0;  //0000 0000

current flag |= 4;

//current flag = 0000 0010 or (4)

current flag |= 32

//current flag = 0001 0010 or (36)

current flag |= 4

//current flag = 0001 0010 or (36)

current flag |= 255

//current flag = 1111 1111 or (255) 


etc. etc. ad naseum.
Last edited on Feb 27, 2015 at 12:51am
Topic archived. No new replies allowed.