Mercurial > hg > Members > kaito > longjump
annotate global_longjump.c @ 16:6ec369858a50 default tip
aua
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 24 Jan 2014 00:10:05 +0900 |
parents | 4e7858590985 |
children |
rev | line source |
---|---|
5
4e7858590985
remove malloc , free and include<stdlib.h>
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
1 /* |
4e7858590985
remove malloc , free and include<stdlib.h>
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
2 please use pointer version. that is spuerior to this. |
4e7858590985
remove malloc , free and include<stdlib.h>
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
3 */ |
4e7858590985
remove malloc , free and include<stdlib.h>
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
4 |
4e7858590985
remove malloc , free and include<stdlib.h>
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
4
diff
changeset
|
5 |
0 | 6 #include <stdio.h> |
7 #include <setjmp.h> | |
8 #include <stdlib.h> | |
9 | |
10 int retval; | |
4
d75a89b10176
write pointer_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
3
diff
changeset
|
11 |
d75a89b10176
write pointer_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
3
diff
changeset
|
12 __code code1(int n,__code(*__return)(int,void *),void *__environment){ |
3
e6aa3b678e4a
remove ret from global_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
13 printf("code1 : code1 entry\n"); |
4
d75a89b10176
write pointer_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
3
diff
changeset
|
14 goto __return(n,__environment); |
0 | 15 } |
16 | |
3
e6aa3b678e4a
remove ret from global_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
17 __code return1 (int n,void* env){ |
e6aa3b678e4a
remove ret from global_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
18 printf("return1 : __return entry\n"); |
0 | 19 retval = n; |
20 longjmp(*(jmp_buf*)env,1); | |
21 } | |
22 | |
23 int main1 (){ | |
3
e6aa3b678e4a
remove ret from global_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
24 __code (*__return)(); |
4
d75a89b10176
write pointer_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
3
diff
changeset
|
25 void *__environment; |
3
e6aa3b678e4a
remove ret from global_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
26 printf("main1 : main1 entry\n"); |
4
d75a89b10176
write pointer_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
3
diff
changeset
|
27 __environment = (void*)malloc(sizeof(jmp_buf)); |
d75a89b10176
write pointer_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
3
diff
changeset
|
28 if (setjmp(__environment)){ |
d75a89b10176
write pointer_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
3
diff
changeset
|
29 free(__environment); |
3
e6aa3b678e4a
remove ret from global_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
30 printf("main1 : main1 return\n"); |
0 | 31 return retval; |
32 } | |
3
e6aa3b678e4a
remove ret from global_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
33 __return = return1; |
4
d75a89b10176
write pointer_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
3
diff
changeset
|
34 goto code1(30,__return,__environment); |
0 | 35 return 0; |
36 } | |
37 | |
38 int main (){ | |
39 int n; | |
40 n = main1(); | |
3
e6aa3b678e4a
remove ret from global_longjump.c
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
41 printf("main : return = %d\n",n); |
0 | 42 return 1; |
43 } |