diff --git a/c_expert/chapter6/setjmp_test.c b/c_expert/chapter6/setjmp_test.c new file mode 100644 index 0000000..27b87fc --- /dev/null +++ b/c_expert/chapter6/setjmp_test.c @@ -0,0 +1,23 @@ +#include +#include +jmp_buf buf; + + +void banana(void) +{ + printf("in banana() \n"); + longjmp(buf, 1); + /* 一下代码不会被执行 */ + printf("you'll never see this, because i longjmp'd"); +} + +int main(void) +{ + if (setjmp(buf)){ + printf("back in main \n"); + }else{ + printf("first time throught\n"); + banana(); + } + return 0; +}