jmp_flow.cpp 582 B

12345678910111213141516171819202122232425262728
  1. /*
  2. # http://blog.csdn.net/win_lin/article/details/40948277
  3. # for all supports setjmp and longjmp:
  4. g++ -g -O0 -o jmp_flow jmp_flow.cpp
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <setjmp.h>
  9. jmp_buf context_level_0;
  10. void func_level_0()
  11. {
  12. const char* level_0_0 = "stack variables for func_level_0";
  13. int ret = setjmp(context_level_0);
  14. printf("func_level_0 ret=%d\n", ret);
  15. if (ret != 0) {
  16. printf("call by longjmp.\n");
  17. exit(0);
  18. }
  19. }
  20. int main(int argc, char** argv)
  21. {
  22. func_level_0();
  23. longjmp(context_level_0, 1);
  24. return 0;
  25. }