comparison pointer_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 6d11ed2a5bed
comparison
equal deleted inserted replaced
-1:000000000000 0:dee9711aeb06
1 #include <stdio.h>
2 #include <setjmp.h>
3 #include <stdlib.h>
4
5 int retval;
6 __code code1(int n,void *__return,void *__enviroment){
7 void(*ret)(int,void *);
8 printf("code1\n");
9 ret = (void(*)(int,void *))__return;
10 ret(n,__enviroment);
11 }
12
13 void *return1 (int n,void* env){
14 printf("return1\n");
15 retval = n;
16 longjmp(*(jmp_buf*)env,1);
17 }
18
19 int main1 (){
20 void *__return;
21 void *__enviroment;
22 printf("main1 entry\n");
23 __enviroment = (void*)malloc(sizeof(jmp_buf));
24 if (setjmp(__enviroment)){
25 free(__enviroment);
26 printf("main1 return\n");
27 return retval;
28 }
29 __return = (void*)return1;
30 goto code1(30,__return,__enviroment);
31 return 0;
32 }
33
34 int main (){
35 int n;
36 n = main1();
37 printf("returned\n");
38 printf("return = %d\n",n);
39 return 1;
40 }