comparison CbC-examples/test_return.c @ 16:4c6926a2b9bc

examples.
author kent <kent@cr.ie.u-ryukyu.ac.jp>
date Thu, 24 Sep 2009 12:51:25 +0900
parents
children
comparison
equal deleted inserted replaced
15:11a6cbe2d14c 16:4c6926a2b9bc
1 #include<stdio.h>
2
3 #if 0
4 typedef float testtype;
5 testtype good = 33.3f;
6 testtype bad = 0.0f;
7 void print_testtype(testtype t)
8 {
9 printf("return value = %2.3f good=%2.3f,bad=%2.3f\n", t,good,bad);
10 }
11 #elif 1
12 typedef char testtype;
13 testtype good = 33;
14 testtype bad = 0;
15 void print_testtype(testtype t)
16 {
17 printf("return value = %d, good=%d,bad=%d\n", t,good,bad);
18 }
19 #elif 0
20 typedef double testtype;
21 testtype good = 333.3;
22 testtype bad = 0.00;
23 void print_testtype(testtype t)
24 {
25 printf("return value = %3.3lf, good=%3.3lf,bad=%3.3lf\n", t,good,bad);
26 }
27 #elif 0
28 typedef
29 struct {
30 int a;
31 float b;
32 int c[4];
33 } testtype;
34 testtype good = {33, 33.3, {4,4,4,4}};
35 testtype bad = {0, 00.0, {0,0,0,0}};
36 void print_testtype(testtype t)
37 {
38 printf( "return value = {\n"
39 " a = %d\n"
40 " b = %2.3f\n"
41 " c = { %d, %d, %d, %d }"
42 "}\n", t.a, t.b,
43 t.c[0],t.c[1],t.c[2],t.c[3]);
44 }
45 #else
46 typedef int testtype;
47 testtype good = 33;
48 testtype bad = 0;
49 void print_testtype(testtype t)
50 {
51 printf("return value = %d, good=%d,bad=%d\n", t,good,bad);
52 }
53 #endif
54
55 typedef void (*RET_FUNC)(testtype, void *);
56
57 void g(RET_FUNC func)
58 {
59 func(good, NULL);
60 }
61
62 testtype f_cbc()
63 {
64 //__label__ _cbc_exit0;
65 //int retval;
66 void *ret;
67
68 ret = _CbC_return;
69
70 printf("f0: fp = %p\n", __builtin_frame_address(0));
71 printf("__return_func = %p\n", ret);
72 g(ret);
73
74 printf("not good\n");
75 return bad;
76 //_cbc_exit0:
77 //printf("f1: fp = 0x%x\n", __builtin_frame_address(0));
78 //return retval;
79 }
80
81 int main(int argc, char **argv)
82 {
83 testtype t;
84 printf("main before: fp = %p\n", __builtin_frame_address(0));
85 t = f_cbc();
86 print_testtype(t);
87 printf("main after: fp = %p\n", __builtin_frame_address(0));
88 }
89