tags:

views:

158

answers:

4

What does the | mean?

m_pD3DDevice->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
+9  A: 

This is a variable (probably referring to a member of this, as m_* is a naming convention):

m_pD3DDevice

This is a method call

->SetFVF( ... )

This is the bitwise-OR of two flag constants, which is a means of combining them together:

D3DFVF_XYZ | D3DFVF_DIFFUSE

bitwise OR takes the logical OR function of each pair of bits from its operands. So, for example given values

D3DFVF_XYZ =     00000010 = 2
D3DFVF_DIFFUSE = 00010000 = 16
bitwise OR =     00010010 = 18

The way that | is usually used, to combine individual bit values, means that it can often be replaced with plain old +.

Potatoswatter
"This is a variable". From the name, most likely a data member of a class, and the code appears in a member function of that class.
Steve Jessop
@Steve: yep, updated.
Potatoswatter
@Potatoswatter but you still didn't explain what bitwise-OR means :)
ruslik
@ruslik: LOL, I completely overlooked the bar in the question. I read "what does this mean?"
Potatoswatter
+6  A: 

It's a bitwise or function.

D3DFVF_XYZ and DFDFVF_DIFFUSE are most probabaly masks.

For example:

0x01 | 0x08 = 0x09
Starkey
+1 for answering the OP's real question.
musicfreak
A: 

m_pD3DDevice

This is probably a member data, whose type is a pointer (possibly to a class named D3DDevice).

->

This means "dereference the pointer"

SetFVF

This is a member method (of the D3DDevice class).

D3DFVF_XYZ | D3DFVF_DIFFUSE

This is a parameter value (probably a pair of bit-values) passed to the SetFVF method.

ChrisW
A: 

The "|" is the "bitwise OR" operator. When used like it is in your code sample, it tells the called library function that you want to enable multiple options. In other words, you are saying that you want both D3DFVF_XYZ AND D3DFVF_DIFFUSE.

It is possibly somewhat counterintuitive to use "bitwise OR" to mean "AND". This is an artifact of the way that bitwise logic works with binary number values. You don't need to know the actual values of these two constants, but you should understand that they are binary values, each with a single bit set to one (each uses a different bit). When you use the bitwise OR operator to combine the values, the resulting value has both bits set. The library can easily evaluate the result to determine which options you want. If you would have used the "bitwise AND" operator "&" instead of "bitwise OR", the result of the expression would be zero -- conveying the wrong information.

This is a common method of configuring software libraries.

nobar