[fpc-pascal] Coroutines and VirtualAlloc

Michael Van Canneyt michael at freepascal.org
Wed Apr 19 11:33:43 CEST 2017



On Wed, 19 Apr 2017, Ryan Joseph wrote:

>
>> On Apr 19, 2017, at 4:14 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>> 
>> Those functions simply store (setjmp) and restore (longjmp) register values (and setjmp also returns the value passed to longjmp if it had been reached by a longjmp). Nothing more, nothing less. So while the stack register while be changed, the contents on the stack will not.
>
> Why doesn’t “i” in my example increment?  The value keeps going back to 1
> even after I used += 1 so its like the old copy of the stack before the
> jump got pushed back on top and it started over.  I don’t understand how
> assembly works but I thought it would just start over and the state of the
> stack in that function would still be the same as before so I could keep
> adding 1 every pass.

The stack remains untouched by setjmp/longjmp.

Your reasoning contains a wrong assumption, namely that I is on the stack.

If I is a register variable, then it is not on the stack, and will be reset
with each longjmp.

Michael.


More information about the fpc-pascal mailing list