view global_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 d75a89b10176
children
line wrap: on
line source

/*
  please use pointer version. that is spuerior to this.
 */


#include <stdio.h>
#include <setjmp.h>
#include <stdlib.h>

int retval;

__code code1(int n,__code(*__return)(int,void *),void *__environment){
  printf("code1 : code1 entry\n");
  goto __return(n,__environment);
}

__code return1 (int n,void* env){
  printf("return1 : __return entry\n");
  retval = n;
  longjmp(*(jmp_buf*)env,1);
}

int main1 (){
  __code (*__return)();
  void *__environment;
  printf("main1 : main1 entry\n");
  __environment = (void*)malloc(sizeof(jmp_buf));
  if (setjmp(__environment)){
    free(__environment);
    printf("main1 : main1 return\n");
    return retval;
  }
  __return = return1;
  goto code1(30,__return,__environment);
  return 0;
}

int main (){
  int n;
  n = main1();
  printf("main : return = %d\n",n);
  return 1;
}