Mercurial > hg > Members > kaito > longjump
comparison pointer_longjump.c @ 5:4e7858590985
remove malloc , free and include<stdlib.h>
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 23 Nov 2013 23:31:02 +0900 |
parents | d75a89b10176 |
children | 509523ee1e27 |
comparison
equal
deleted
inserted
replaced
4:d75a89b10176 | 5:4e7858590985 |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include <setjmp.h> | 2 #include <setjmp.h> |
3 #include <stdlib.h> | |
4 | 3 |
5 __code code1(int n,__code(*__return)(int,void *,int *),void *__environment,int *__ret_p){ | 4 __code code1(int n,__code(*__return)(int,void *,int *),void *__environment,int *__ret_p){ |
6 printf("code1 : code entry1\n"); | 5 printf("code1 : code entry1\n"); |
7 goto __return(n,__environment,__ret_p); | 6 goto __return(n,__environment,__ret_p); |
8 } | 7 } |
13 longjmp(*(jmp_buf*)env,1); | 12 longjmp(*(jmp_buf*)env,1); |
14 } | 13 } |
15 | 14 |
16 int main1 (){ | 15 int main1 (){ |
17 __code (*__return)(); | 16 __code (*__return)(); |
18 void *__environment; | 17 void *__environment ; |
19 int retval; | 18 int retval; |
20 int *__ret_p; | 19 int *__ret_p; |
20 jmp_buf j_buf; | |
21 __ret_p = &retval; | 21 __ret_p = &retval; |
22 printf("main1 : main1 entry\n"); | 22 printf("main1 : main1 entry\n"); |
23 __environment = (void*)malloc(sizeof(jmp_buf)); | 23 __environment = &j_buf; |
24 if (setjmp(__environment)){ | 24 if (setjmp(__environment)){ |
25 free(__environment); | |
26 printf("main1 : main1 return\n"); | 25 printf("main1 : main1 return\n"); |
27 return retval; | 26 return retval; |
28 } | 27 } |
29 __return = return1; | 28 __return = return1; |
30 goto code1(30,__return,__environment,__ret_p); | 29 goto code1(30,__return,__environment,__ret_p); |