Mercurial > hg > Members > kaito > longjump
changeset 13:89d24aeb122e
add goal.c
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 12 Jan 2014 19:21:18 +0900 |
parents | 7c8d5d4074b8 |
children | 1cd0fad44dac |
files | goal.c |
diffstat | 1 files changed, 36 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/goal.c Sun Jan 12 19:21:18 2014 +0900 @@ -0,0 +1,36 @@ +#include <stdio.h> +#include <setjmp.h> +#include <stdlib.h> + +__attribute__((noinline)) +__code code1(void *__return,void *__enviroment){ + void(*ret)(void *); + printf("code1\n"); + ret = (void(*)(void *))__return; + ret(__enviroment); +} + +void *return1 (void* env){ + printf("return1\n"); + longjmp(*(jmp_buf*)env,1); +} + +void main1 (){ + void *__return; + void *__enviroment; + printf("main1 entry\n"); + __enviroment = (void*)malloc(sizeof(jmp_buf)); + if (setjmp(__enviroment)){ + free(__enviroment); + printf("main1 return\n"); + return; + } + __return = (void*)return1; + goto code1(__return,__enviroment); +} + +int main (){ + main1(); + printf("returned\n"); + return 1; +}