Stuck trying to convert Petzolds sysmets C code to Goasm

Started by Dogim, November 10, 2010, 03:25:08 PM

Previous topic - Next topic

Yuri

Each message is processed in a separate call to WndProc. So, you write to the variables in one call and read from them in another. Local variables are created on the stack and exist only within one call to the function. Another call may create them in a different place on the stack or they may have been overwritten with some other data by calls to other functions.

Dogim

Quote from: Yuri on November 12, 2010, 07:47:37 AM
Each message is processed in a separate call to WndProc. So, you write to the variables in one call and read from them in another. Local variables are created on the stack and exist only within one call to the function. Another call may create them in a different place on the stack or they may have been overwritten with some other data by calls to other functions.
Hi Yuri, thanks for your answer, but i can't follow, why does it work with variables as global and local structures,these structures and the buffer are also created on the stack, shouldn't this also give problems ?

Yuri

Yes, the structures are local, but you don't divide their use between function calls. Functions that you call from within WndProc can't damage the structures, because those functions are executed in their own stack frames beyond the one of WndProc. The local data in WndProc's frame gets invalid only when you return from WndProc. While you are in, it's safe. But the processing of WM_PAINT will occur in one of the later calls to WndProc, not in this one, so the data should be saved in global variables before you return from this call to WndProc.

Dogim

Quote from: Yuri on November 12, 2010, 04:36:28 PM
Yes, the structures are local, but you don't divide their use between function calls. Functions that you call from within WndProc can't damage the structures, because those functions are executed in their own stack frames beyond the one of WndProc. The local data in WndProc's frame gets invalid only when you return from WndProc. While you are in, it's safe. But the processing of WM_PAINT will occur in one of the later calls to WndProc, not in this one, so the data should be saved in global variables before you return from this call to WndProc.
Thanks Yuri, glad with the explanation, thanks for your time.  :U