c setjmp longjmp

http://coolshell.cn/?s=setjmp
http://www.cnblogs.com/hazir/p/c_setjmp_longjmp.html
 1 double divide(double to, double by, jmp_buf env)
 2 {
 3     if(by == 0)
 4         if (env)
 5             longjmp(env, 1);
 6         else
 7             return 0;
 8     else
 9         return to/by;
10 }
11 
12 void f()
13 {
14     jmp_buf env;
15     int ret = setjmp(env);
16     printf("jmp: %d
", ret); 17 if(ret == 0) 18 { 19 printf("result: %lf
", divide(2.0, 0, env)); 20 } 21 else 22 { 23 printf("error: %d
", ret); 24 } 25 }

좋은 웹페이지 즐겨찾기