view CbC-examples/code_segment_pointer_check/code_segment_check.cbc @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents f9b1a53df341
children
line wrap: on
line source

#include<stdio.h>
#include<stdlib.h>
#define dprint(f, args...) \
	printf("in %s env=%p: "f, __FUNCTION__, __builtin_frame_address(1), ## args)

/*
 * コードセグメント間の遷移をテスト
 *
 */

__code end (int a);
__code cs0a (int a, double b, int c, float d, char e);
__code cs1a (char e, int a, double b, int c, float d);
__code cs2a (float d, char e, int a, double b, int c);
__code cs3a (int c, float d, char e, int a, double b);
__code cs4a (double b, int c, float d, char e, int a);
int main ();

__code end(int a) {
	dprint("exit code is %d\n",a);
	exit(a);
}

int i=0;
__code cs0a(int a, double b, int c, float d, char e) {
	if ( i++ >= 10 ) {
		dprint("int a=%d,double b=%2.3lf,int c=%d,float d=%2.3f,char e=%d\n", a, b, c, d, e);
		goto end((int)(a*b*c*d*e));
	}
	goto cs1a(e, a, b, c, d);
}
__code cs1a(char e, int a, double b, int c, float d) {
	//dprint("int a=%d,double b=%2.3lf,int c=%d,float d=%2.3f,char e=%d\n", a, b, c, d, e);
	goto cs2a(d, e, a, b, c);
}
__code cs2a(float d, char e, int a, double b, int c) {
	//dprint("int a=%d,double b=%2.3lf,int c=%d,float d=%2.3f,char e=%d\n", a, b, c, d, e);
	goto cs3a(c, d, e, a, b);
}
__code cs3a(int c, float d, char e, int a, double b) {
	//dprint("int a=%d,double b=%2.3lf,int c=%d,float d=%2.3f,char e=%d\n", a, b, c, d, e);
	goto cs4a(b, c, d, e, a);
}
__code cs4a(double b, int c, float d, char e, int a) {
	//dprint("int a=%d,double b=%2.3lf,int c=%d,float d=%2.3f,char e=%d\n", a, b, c, d, e);
	goto cs0a(a, b, c, d, e);
}

__code starter(int a, double b, int c, float d, char e) {
	dprint("exit code is expected to %d\n",(int)(a*b*c*d*e));
	dprint("int a=%d,double b=%2.3lf,int c=%d,float d=%2.3f,char e=%d\n", a, b, c, d, e);
	goto cs0a(a,b,c,d,e);
}
int main() {
	goto starter(11, 22.2, 33, 44.44, 55);
}