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