Posts

Showing posts from June, 2013

setjmp and longjmp

In short, functions setjmp and longjmp just work like label&goto instruction, except that the combination of label&goto only can be used within the same function which means you cannot goto the label outside the function. But the combination of setjmp and longjmp can be used anywhere in the whole program . For example, we use  label&goto  to implement a jump function: main() {      int a=1, b=2, c=0; label :      c=a+b;       goto label ;       } Now we implement the same function using setjmp and longjmp: typedef long jmp_buf[16]; main() {      int a=1, b=2, c=0;      jmp_buff environment;       setjmp (evironment) ;      c=a+b;       longjmp(evironment, 1) ; } So from above, we can see the jump buffer environment contains all the context around the setjmp function , so i...