diff CbC-examples/test_csp1.c @ 16:4c6926a2b9bc

examples.
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Thu, 24 Sep 2009 12:51:25 +0900
parents
children f9b1a53df341
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CbC-examples/test_csp1.c	Thu Sep 24 12:51:25 2009 +0900
@@ -0,0 +1,48 @@
+#include<stdio.h>
+#include<stdlib.h>
+
+//static __code (*csp)(int, int, int, int);
+
+__code cs_end(int a){
+	printf("cs_exit : a=%d.\n", a);
+	exit(a);
+	goto cs_end(a);
+}
+
+__code cs0(int a, int b, int c, int d){
+	//printf("cs0     : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d.\n", a, b, c, d, e, f, g);
+	printf("cs_cs0  : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d);
+	goto cs_end( (int)(20*a + 30*b + 40*c + 50*d) );
+}
+
+
+void* freturn(){
+	return cs0;
+}
+__code cs_goto(int a, int b, int c, int d){
+	__code (*csp)(int, int, int, int);
+	csp = freturn();
+	printf("csp = %x.\n", csp);
+
+	//printf("cs_goto : a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d.\n", a, b, c, d, e, f, g);
+	//printf("cs_goto : a=%d, b=%d, c=%d, d=%d.\n", a, b, c, d);
+	//printf("cs_goto : a-4=%d, a-8=%d, a-12=%d, a-16=%d.\n", *(&a-4), *(&a-8), *(&a-12), *(&a-16));
+	//printf("cs_goto : cs0(a, b, c, d)\n");
+	goto csp(b+a, d+b, a+c, c+d);
+}
+
+int function(double a, float b, int c){
+
+	printf("function:\n");
+	printf("a=%lf, b=%f, c=%d\n", a, b, c);
+	//goto cs_goto(10, 20, 30, 40);
+	goto cs_goto(10, 20, 30, 40);
+}
+
+int main(int argc, char **argv){
+	//csp = cs0;
+	function(10.01, 20.02, 30);
+	return 0;
+}
+
+