annotate global_longjump.c @ 0:dee9711aeb06

the first commit
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Tue, 12 Nov 2013 11:32:39 +0900
parents
children e6aa3b678e4a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <stdio.h>
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include <setjmp.h>
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <stdlib.h>
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 int retval;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 __code code1(int n,void *__return,void *__enviroment){
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 void(*ret)(int,void *);
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 printf("code1\n");
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 ret = (void(*)(int,void *))__return;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 ret(n,__enviroment);
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 }
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 void *return1 (int n,void* env){
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 printf("return1\n");
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 retval = n;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 longjmp(*(jmp_buf*)env,1);
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 }
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 int main1 (){
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 void *__return;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 void *__enviroment;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 printf("main1 entry\n");
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 __enviroment = (void*)malloc(sizeof(jmp_buf));
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 if (setjmp(__enviroment)){
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 free(__enviroment);
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 printf("main1 return\n");
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 return retval;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 }
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 __return = (void*)return1;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 goto code1(30,__return,__enviroment);
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 return 0;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 }
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 int main (){
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 int n;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 n = main1();
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 printf("returned\n");
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 printf("return = %d\n",n);
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 return 1;
dee9711aeb06 the first commit
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 }