forked from spevnev/uprintf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.c
86 lines (66 loc) · 2.63 KB
/
function.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "uprintf.h"
typedef int *(*fun0_t)(void);
typedef struct {
int num;
fun0_t f0;
} Result;
typedef Result *(*fun_t)(void);
typedef fun_t (*fun1_t)(void);
typedef struct {
fun1_t f;
fun1_t *fp;
} Functions;
static int num = 200;
__attribute__((noinline)) int *fun0(void) { return # }
static Result result = {
.num = 100,
.f0 = fun0,
};
__attribute__((noinline)) Result *fun(void) { return &result; }
__attribute__((noinline)) fun_t fun1(void) { return fun; }
__attribute__((noinline)) fun1_t fun2(void) { return fun1; }
int main(void) {
uprintf("&fun2: %S\n", &fun2);
uprintf("fun2(): %S\n", fun2());
uprintf("fun2()(): %S\n", fun2()());
uprintf("fun2()()(): %S\n", fun2()()());
uprintf("fun2()()().num: %S\n", &fun2()()()->num);
uprintf("fun2()()().f0: %S\n", fun2()()()->f0);
uprintf("&fun2()()().f0: %S\n", &fun2()()()->f0);
uprintf("fun2()()().f0(): %S\n", fun2()()()->f0());
fun_t var_fun = fun;
fun1_t var_fun1 = fun1;
fun_t *ptr_fun = &var_fun;
uprintf("&var_fun: %S\n", &var_fun);
uprintf("var_fun(): %S\n", var_fun());
uprintf("var_fun().num: %S\n", &var_fun()->num);
uprintf("var_fun().f0: %S\n", var_fun()->f0);
uprintf("&var_fun().f0: %S\n", &var_fun()->f0);
uprintf("var_fun().f0(): %S\n", var_fun()->f0());
uprintf("ptr_fun: %S\n", ptr_fun);
uprintf("(*ptr_fun)(): %S\n", (*ptr_fun)());
uprintf("(*ptr_fun)().num: %S\n", &(*ptr_fun)()->num);
uprintf("(*ptr_fun)().f0: %S\n", (*ptr_fun)()->f0);
uprintf("&(*ptr_fun)().f0: %S\n", &(*ptr_fun)()->f0);
uprintf("(*ptr_fun)().f0(): %S\n", (*ptr_fun)()->f0());
Functions functions = {
.f = fun1,
.fp = &var_fun1,
};
uprintf("&functions: %S\n", &functions);
uprintf("&functions.f: %S\n", &functions.f);
uprintf("functions.f(): %S\n", functions.f());
uprintf("functions.f()(): %S\n", functions.f()());
uprintf("functions.f()().num: %S\n", &functions.f()()->num);
uprintf("functions.f()().f0: %S\n", functions.f()()->f0);
uprintf("&functions.f()().f0: %S\n", &functions.f()()->f0);
uprintf("functions.f()().f0()(): %S\n", functions.f()()->f0());
uprintf("functions.fp: %S\n", functions.fp);
uprintf("(*functions.fp)(): %S\n", (*functions.fp)());
uprintf("(*functions.fp)()(): %S\n", (*functions.fp)()());
uprintf("(*functions.fp)()().num: %S\n", &(*functions.fp)()()->num);
uprintf("(*functions.fp)()().f0: %S\n", (*functions.fp)()()->f0);
uprintf("&(*functions.fp)()().f0: %S\n", &(*functions.fp)()()->f0);
uprintf("(*functions.fp)()().f0()(): %S\n", (*functions.fp)()()->f0());
return _upf_test_status;
}