| ForRealzZzZ (6) | |||
Ive been following petzolds book and understanding everything line by line up until this example(Im very OCD about that). Im not very fluent in C I started with C++ and worked my way up, is this C? y << 8 | x;and here are the callbacks for the example there is one in the child window creation loop and above the WM_SETFOCUS message callback.
| |||
|
Last edited on
|
|||
| freddie1 (847) | |||
idFocus is the result of shifting whatever is in y leftward 8 bits and or'ing this later quantity against whatever is in x. Using code tags would help. That syntax isn't unique to C. | |||
|
Last edited on
|
|||
| ForRealzZzZ (6) | |
|
Thanks there was no explanation in the book about this and the future examples were the same so i was left scratching my head. So when you use the << operator your really pushing bits to encompass the stuff on the right side. So in essence its the same as allocating memory for a value or a string in assembly? | |
|
Last edited on
|
|
| freddie1 (847) | |
| I don't know if I'd put it that way. Do a search on C Bitwise Shift Operators or C Shift Operators and that will explain it if you aren't familiar with it. I havn't done assembly in ages, but if I recall correctly there were SHL and SHR or something like that for shifting bits around. They just move them about within a variable. If there isn't room the one's on the left or right edge just disappear or rotate around to the other side. But in your example, I see x and y are ints, so they've got 32 bits. So whatever the bits are they all get shifted left 8 bits. Then x, which may be functioning as a bit mask, gets or'ed against whatever is now in y. idFocus gets the result of those manipulations. I'm not familiar with that Petzold example, but he was a master at those kinds of things! | |
|
|
|