-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
120 lines (90 loc) · 1.93 KB
/
main.c
File metadata and controls
120 lines (90 loc) · 1.93 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <stdio.h>
#include "ciallo.h"
/**
* test1 receives NULL
*/
void test1(void *arg);
/**
* test2 receives a int pointer,
* the pointer stores the return value address
*/
void test2(void *arg);
/**
* test3 receives a struct pointer,
* member1 and member2 are parameters,
* member3 stores the return value address
*/
void test3(void *arg);
/**
* main->(init)
* ->main->(call test1)
* ->test1->(init)
* ->main->(switch)
* ->test1->(switch)
* ->main->...
* ->main->(switch)
* ->test1->(exit)
* ->main->...
*/
int main(void) {
Ciaolima; // init
Ciallo(test1, NULL); // call test1
for (int i = 0; i < 10; i++) {
printf("main:%d\n", i);
Ciallo_; // switch to another function
}
int result;
Ciallo(test2, &result); // call test2
Ciallo_;
for (int i = 10; i < 20; i++) {
printf("main:%d\n", i);
Ciallo_;
}
Ciallo_;
Ciallo_;
Ciallo_;
Ciallo_;
Ciallo_;
Ciallo_;
printf("main:test2_result=%d\n", result);
return 0;
}
void test1(void *arg) {
Ciaolima;
for (int i = 0; i < 10; i++) {
printf("test1:%d\n", i);
Ciallo_;
}
Ciavanllo; // exit
}
void test2(void *arg) {
Ciaolima;
int result = 0;
for (int i = 0; i < 10; i++) {
result += i;
printf("test2:%d\n", result);
Ciallo_;
}
*(int *)arg = result;
result = 0;
struct {
int a;
int b;
int *res;
} arg_abaaba = {7, 21, &result};
Ciallo(test3, &arg_abaaba);
Ciallo_;
Ciallo_;
printf("test1:test3_result=%d\n", result);
Ciavanllo;
}
void test3(void *arg) {
Ciaolima;
struct {
int a;
int b;
int *result;
} *arg_abaaba = arg;
*arg_abaaba->result = arg_abaaba->a + arg_abaaba->b;
Ciavanllo;
}