forked from zhaojh329/lua-ffi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
67 lines (54 loc) · 918 Bytes
/
test.c
File metadata and controls
67 lines (54 loc) · 918 Bytes
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
// gcc -shared -fPIC test.c -o libtest.so
#include <stdlib.h>
#include <string.h>
struct student {
int age;
char name[0];
};
int student_get_age(struct student st)
{
return st.age;
}
int student_get_age_ptr(struct student *st)
{
return st->age;
}
const char *student_get_name(struct student *st)
{
return st->name;
}
struct student *student_new(int age, const char *name)
{
struct student *st = malloc(sizeof(struct student) + strlen(name) + 1);
st->age = age;
strcpy(st->name, name);
return st;
}
int *pass_array(int a[])
{
return a;
}
int cb_mul10(int i)
{
return i * 10;
}
int call_f0(int (*cb)(int))
{
return cb(20);
}
int call_f1(int (*cb)(int), int x)
{
return cb(x);
}
int call_f2(int (*cb)(int i), int x)
{
return cb(x);
}
int call_f3(int x, int (*cb)(int i))
{
return cb(x);
}
int call_f4(int x, int (*cb)(int i))
{
return cb(x);
}