comparison global_longjump.c @ 3:e6aa3b678e4a

remove ret from global_longjump.c
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Tue, 12 Nov 2013 15:22:04 +0900
parents dee9711aeb06
children d75a89b10176
comparison
equal deleted inserted replaced
2:76cd6ae48a1b 3:e6aa3b678e4a
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <setjmp.h> 2 #include <setjmp.h>
3 #include <stdlib.h> 3 #include <stdlib.h>
4 4
5 int retval; 5 int retval;
6 __code code1(int n,void *__return,void *__enviroment){ 6 __code code1(int n,__code(*__return)(int,void *),void *__enviroment){
7 void(*ret)(int,void *); 7 printf("code1 : code1 entry\n");
8 printf("code1\n"); 8 goto __return(n,__enviroment);
9 ret = (void(*)(int,void *))__return;
10 ret(n,__enviroment);
11 } 9 }
12 10
13 void *return1 (int n,void* env){ 11 __code return1 (int n,void* env){
14 printf("return1\n"); 12 printf("return1 : __return entry\n");
15 retval = n; 13 retval = n;
16 longjmp(*(jmp_buf*)env,1); 14 longjmp(*(jmp_buf*)env,1);
17 } 15 }
18 16
19 int main1 (){ 17 int main1 (){
20 void *__return; 18 __code (*__return)();
21 void *__enviroment; 19 void *__enviroment;
22 printf("main1 entry\n"); 20 printf("main1 : main1 entry\n");
23 __enviroment = (void*)malloc(sizeof(jmp_buf)); 21 __enviroment = (void*)malloc(sizeof(jmp_buf));
24 if (setjmp(__enviroment)){ 22 if (setjmp(__enviroment)){
25 free(__enviroment); 23 free(__enviroment);
26 printf("main1 return\n"); 24 printf("main1 : main1 return\n");
27 return retval; 25 return retval;
28 } 26 }
29 __return = (void*)return1; 27 __return = return1;
30 goto code1(30,__return,__enviroment); 28 goto code1(30,__return,__enviroment);
31 return 0; 29 return 0;
32 } 30 }
33 31
34 int main (){ 32 int main (){
35 int n; 33 int n;
36 n = main1(); 34 n = main1();
37 printf("returned\n"); 35 printf("main : return = %d\n",n);
38 printf("return = %d\n",n);
39 return 1; 36 return 1;
40 } 37 }