fork download
  1. #include <stdio.h>
  2. #include <setjmp.h>
  3.  
  4. jmp_buf jb;
  5.  
  6. void some_func (void)
  7. {
  8. register int a = 1;
  9.  
  10. if (setjmp(jb) == 0) {
  11. a = 7;
  12.  
  13. // do something
  14. printf("a = %d (initialized)\n", a);
  15.  
  16. // use longjmp to make `a` not initialized
  17. longjmp(jb, 1);
  18. // NOTREACHED
  19. } else {
  20. printf("a = %d (not initialized)\n", a);
  21. }
  22. }
  23.  
  24. int main (void)
  25. {
  26. some_func();
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
a = 7 (initialized)
a = 1 (not initialized)