setjmp_test.c 504 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <stdio.h>
  2. #include <setjmp.h>
  3. #include <unistd.h>
  4. jmp_buf jb;
  5. int tries=0;
  6. int main(int argc,char *argv[])
  7. {
  8. int ret;
  9. printf("calling setjmp, should return with 0\n");
  10. ret = setjmp(jb);
  11. printf("setjmp returned %d\n",ret);
  12. if(!ret){
  13. if(tries++>4){
  14. printf("Hmmm... in loop, must be broken.\n");
  15. return 0;
  16. }
  17. printf("now calling longjmp, setjmp should return with 1\n");
  18. longjmp(jb,1);
  19. printf("returned from longjmp, must be broken\n");
  20. return 0;
  21. }
  22. return 0;
  23. }