comparison global_longjump.c @ 4:d75a89b10176

write pointer_longjump.c
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Thu, 14 Nov 2013 13:16:46 +0900
parents e6aa3b678e4a
children 4e7858590985
comparison
equal deleted inserted replaced
3:e6aa3b678e4a 4:d75a89b10176
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,__code(*__return)(int,void *),void *__enviroment){ 6
7 __code code1(int n,__code(*__return)(int,void *),void *__environment){
7 printf("code1 : code1 entry\n"); 8 printf("code1 : code1 entry\n");
8 goto __return(n,__enviroment); 9 goto __return(n,__environment);
9 } 10 }
10 11
11 __code return1 (int n,void* env){ 12 __code return1 (int n,void* env){
12 printf("return1 : __return entry\n"); 13 printf("return1 : __return entry\n");
13 retval = n; 14 retval = n;
14 longjmp(*(jmp_buf*)env,1); 15 longjmp(*(jmp_buf*)env,1);
15 } 16 }
16 17
17 int main1 (){ 18 int main1 (){
18 __code (*__return)(); 19 __code (*__return)();
19 void *__enviroment; 20 void *__environment;
20 printf("main1 : main1 entry\n"); 21 printf("main1 : main1 entry\n");
21 __enviroment = (void*)malloc(sizeof(jmp_buf)); 22 __environment = (void*)malloc(sizeof(jmp_buf));
22 if (setjmp(__enviroment)){ 23 if (setjmp(__environment)){
23 free(__enviroment); 24 free(__environment);
24 printf("main1 : main1 return\n"); 25 printf("main1 : main1 return\n");
25 return retval; 26 return retval;
26 } 27 }
27 __return = return1; 28 __return = return1;
28 goto code1(30,__return,__enviroment); 29 goto code1(30,__return,__environment);
29 return 0; 30 return 0;
30 } 31 }
31 32
32 int main (){ 33 int main (){
33 int n; 34 int n;