Line 132 states:
window_signal = 1L << MyWindow->UserPort->mp_SigBit;
What I don't understand is why he has to bitshift it to the left.
MyWindow->UserPort->mp_SigBit holds the number of the particular bit used to represent the message signal for MyWindow. So, if MyWindow->UserPort->mp_SigBit happens to be 26, then we will shift the 1 to the left 26 places:
00000010 00000000 00000000 00000000
Why could he not just use:
window_signal = MyWindow->UserPort->mp_SigBit;
If mp_SigBit were 3, the shift code would produce this:
.... 00001000
but if you just assigned 3 to window_signal, you would get this:
.... 00000011
It's a one-liner that sets an individual bit to 1.
... that its not the value it would be wih the bit set, but the digit position of the bit?
that's it.
Line 139 to 142:
signals = Wait( window_signal );
/* Check the signal bit for our message port. Will be true if these is a message. */
if ( signals & window_signal )
Why is he using the AND bit operator here?
And is a quick and easy way to filter out what you want. You can use it to test a single bit in a bitfield.
If signals contained 01010101 and you wanted to check the third one from the right, you can do this:
01010101 &
00000100 =
00000100
If the answer is non-zero, then your bit is set, otherwise, it's not set. You'll frequently see this sort of thing as a series of #defines in an include somewhere with the 00000100 declared as a hex value 0x4 in this case. I've also seen the shift operators used in those #defines as well.
brian