setjmp, longjmp looks like continuations in functional languages.
This functions save/restore call contest as it does call/cc.
modified example from there:
http://publications.gbdirect.co.uk/c_book/chapter9/nonlocal_jumps.html
return values (second argument of longjmp example)
[rtg@rtgCent example]$ vi _jmp.c
[rtg@rtgCent example]$ gcc -g _jmp.c -o jmp
[rtg@rtgCent example]$ ./jmp
inside jmp: func
place retval=1
inside jmp: func2
place 2 retval=32
despite of longjmp second parameter set to zero, retval displayed as 1.
Here is example wich shows global and local variables in caller contest change.
_jmp2.c
No comments:
Post a Comment