view test_para3.c @ 17:a4f44624a253

asm longjmp (can return correct address but return value is wrong)
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Sun, 24 Jan 2016 06:01:43 +0900
parents 35d6eabeadb0
children 586096c45873
line wrap: on
line source

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

struct abc {
  int a;
  double b;
  char c;
  double *d;
};

struct def {
  int d;
  struct abc e;
  struct abc *f;
};

void print_abc(struct abc a){
  printf("\tstruct abc:\n");
  printf("\ta=%d, b=%lf, c=%d, d=%p\n", a.a, a.b, a.c, a.d);
}
void print_def(struct def b){
  printf("\tstruct def:\n");
  printf("\td=%d, f=%p\n", b.d, b.f);
  print_abc(b.e);
}

__code cs_exit(int a){
  printf("cs_exit : a=%d.\n", a);
  exit(a);
}

__code cs0(struct abc a, struct def b, int c){
  printf("cs0     :\n");
  printf("c=%d\n", c);
  print_abc(a);
  print_def(b);
  goto cs_exit( c*a.a+b.e.c );
}


__code cs_goto(int c, struct abc a, struct def b){
  printf("cs_goto :\n");
  printf("c=%d\n", c);
  print_abc(a);
  print_def(b);
  goto cs0(a, b, c);
}

int function(){
  struct abc A;
  struct def B;
  A.a = 10, A.b = 20.02, A.c = '\0', A.d = 0xad;
  B.d = 30, B.f = 0xbf;
  B.e.a = 50, B.e.b = 60.06, B.e.c = '\1', B.e.d = 0xed;

  printf("function  :\n");
  print_abc(A);
  print_def(B);
  goto cs_goto(100, A, B);
  return 0;
}

int main(int argc, char **argv){
  struct abc A;
  struct def B;
  A.a = 10, A.b = 20.02, A.c = '\0', A.d = 0xad;
  B.d = 30, B.f = 0xbf;
  B.e.a = 50, B.e.b = 60.06, B.e.c = '\1', B.e.d = 0xed;

  function();
  return 0;
}