# HG changeset patch # User Kaito Tokumori # Date 1384229195 -32400 # Node ID 6d11ed2a5bedab14648eae71ac00023eee1da651 # Parent dee9711aeb06f01cfbc3e2fc881d8ae784dfabb7 write pointer_longjump.c diff -r dee9711aeb06 -r 6d11ed2a5bed pointer_longjump.c --- a/pointer_longjump.c Tue Nov 12 11:32:39 2013 +0900 +++ b/pointer_longjump.c Tue Nov 12 13:06:35 2013 +0900 @@ -2,32 +2,33 @@ #include #include -int retval; -__code code1(int n,void *__return,void *__enviroment){ - void(*ret)(int,void *); +__code code1(int n,void *__return,void *__enviroment,int *__ret_p){ + void(*ret)(int,void *,int *); printf("code1\n"); - ret = (void(*)(int,void *))__return; - ret(n,__enviroment); + ret = (void(*)(int,void *,int *))__return; + ret(n,__enviroment,__ret_p); } -void *return1 (int n,void* env){ +void *return1 (int n,void* env,int* __ret_p){ printf("return1\n"); - retval = n; + *__ret_p = n; longjmp(*(jmp_buf*)env,1); } int main1 (){ void *__return; void *__enviroment; + int *__ret_p; printf("main1 entry\n"); __enviroment = (void*)malloc(sizeof(jmp_buf)); + __ret_p = (int*)malloc(sizeof(int)); if (setjmp(__enviroment)){ free(__enviroment); printf("main1 return\n"); - return retval; + return *__ret_p; } __return = (void*)return1; - goto code1(30,__return,__enviroment); + goto code1(30,__return,__enviroment,__ret_p); return 0; }