-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <tlpi.h> | ||
#include <setjmp.h> | ||
|
||
static jmp_buf env; | ||
|
||
static void f2(void) { | ||
longjmp(env, 2); | ||
} | ||
|
||
static void f1(int argc) { | ||
if(argc == 1) | ||
longjmp(env, 1); | ||
f2(); | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
switch (setjmp(env)) { | ||
case 0: | ||
printf("calling f1() after initial setjmp()\n"); | ||
f1(argc); | ||
break; | ||
|
||
case 1: | ||
printf("came back from f1()\n"); | ||
break; | ||
|
||
case 2: | ||
printf("came back from f2()\n"); | ||
break; | ||
} | ||
exit(EXIT_SUCCESS); | ||
} |