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