setjmp : Set a break point for get back.
longjmp:Go to break point where set up before.
01 #include <stdio.h>
02 #include <setjmp.h>
03
04 jmp_buf _buffer;
05
06 int main( int argc, char* argv[] )
07 {
08 if( setjmp( _buffer ) == 0 )
09 {
10 // do something11
12 // longjmp will go to the break point, and set setjmp( _buffer ) to 1
13 longjmp( _buffer, 1 );
14 }
15 else
16 {
17 // do something
18 }
19 }
13 longjmp( _buffer, 1 );
14 }
15 else
16 {
17 // do something
18 }
19 }
in the instance.
It will execute line number in turn
01...08...13->08->15....19
If line 13 change to longjmp( _buffer, 0 );
It will execute line number in turn
01...08...13->08->09....13->08->09....13->08->09.... (infinite loop)
沒有留言:
張貼留言