view CbC-examples/test_return.c @ 118:fd00160c1b76

ifdef TARGET_64BIT
author mir3636
date Tue, 27 Feb 2018 15:01:35 +0900
parents 4c6926a2b9bc
children
line wrap: on
line source

#include<stdio.h>

#if 0
typedef float testtype;
testtype good = 33.3f;
testtype bad = 0.0f;
void print_testtype(testtype t)
{
	printf("return value = %2.3f  good=%2.3f,bad=%2.3f\n", t,good,bad);
}
#elif 1
typedef char testtype;
testtype good = 33;
testtype bad  = 0;
void print_testtype(testtype t)
{
	printf("return value = %d, good=%d,bad=%d\n", t,good,bad);
}
#elif 0
typedef double testtype;
testtype good = 333.3;
testtype bad  = 0.00;
void print_testtype(testtype t)
{
	printf("return value = %3.3lf, good=%3.3lf,bad=%3.3lf\n", t,good,bad);
}
#elif 0
typedef
struct {
	int a;
	float b;
	int c[4];
} testtype;
testtype good = {33, 33.3, {4,4,4,4}};
testtype bad  = {0, 00.0, {0,0,0,0}};
void print_testtype(testtype t)
{
	printf( "return value = {\n"
			"	a = %d\n"
			"	b = %2.3f\n"
			"	c = { %d, %d, %d, %d }"
			"}\n", t.a, t.b,
			t.c[0],t.c[1],t.c[2],t.c[3]);
}
#else
typedef int testtype;
testtype good = 33;
testtype bad = 0;
void print_testtype(testtype t)
{
	printf("return value = %d,  good=%d,bad=%d\n", t,good,bad);
}
#endif

typedef void (*RET_FUNC)(testtype, void *);

void g(RET_FUNC func)
{
	func(good, NULL);
}

testtype f_cbc()
{
	//__label__ _cbc_exit0;
	//int retval;
	void *ret;

	ret = _CbC_return;

	printf("f0: fp = %p\n", __builtin_frame_address(0));
	printf("__return_func = %p\n", ret);
	g(ret);

	printf("not good\n");
	return bad;
//_cbc_exit0:
	//printf("f1: fp = 0x%x\n", __builtin_frame_address(0));
	//return retval;
}

int main(int argc, char **argv)
{
	testtype t;
	printf("main before: fp = %p\n", __builtin_frame_address(0));
	t = f_cbc();
	print_testtype(t);
	printf("main after: fp = %p\n", __builtin_frame_address(0));
}