view longjump.c @ 6:509523ee1e27

add struct_longjump.c
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Sun, 24 Nov 2013 01:10:16 +0900
parents dee9711aeb06
children
line wrap: on
line source

#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;
}