Mercurial > hg > Members > kaito > longjump
view pointer_longjump.c @ 3:e6aa3b678e4a
remove ret from global_longjump.c
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 12 Nov 2013 15:22:04 +0900 |
parents | 76cd6ae48a1b |
children | d75a89b10176 |
line wrap: on
line source
#include <stdio.h> #include <setjmp.h> #include <stdlib.h> __code code1(int n,void *__return,void *__enviroment,int *__ret_p){ void(*ret)(int,void *,int *); printf("code1\n"); ret = (void(*)(int,void *,int *))__return; ret(n,__enviroment,__ret_p); //((void(*)(int,void *,int *))__return)(n,__enviroment,__ret_p); } void *return1 (int n,void* env,int* __ret_p){ printf("return1\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"); // We haven't freed __ret_p's memory... Where is the best position of the free()? return *__ret_p; } __return = (void*)return1; goto code1(30,__return,__enviroment,__ret_p); return 0; } int main (){ int n; n = main1(); printf("returned\n"); printf("return = %d\n",n); return 1; }