parameters-lib.c revision e3f4a984db115979e09414b7281da98399dd8949
1#include <string.h>
2#include <stdio.h>
3
4void func_ignore(int a, int b, int c)
5{
6	printf("%d\n", a + b + c);
7}
8
9void func_intptr(int *i)
10{
11	printf("%d\n", *i);
12}
13
14void func_intptr_ret(int *i)
15{
16	*i = 42;
17}
18
19int func_strlen(char* p)
20{
21	strcpy(p, "Hello world");
22	return strlen(p);
23}
24
25void func_strfixed(char* p)
26{
27	strcpy(p, "Hello world");
28}
29
30void func_string(char* p)
31{
32	printf("%s\n", p);
33}
34
35void func_ppp(int*** ppp)
36{
37	printf("%d\n", ***ppp);
38}
39
40void func_stringp(char** sP)
41{
42	printf("%s\n", *sP);
43}
44
45void func_enum(int x)
46{
47	printf("enum: %d\n", x);
48}
49
50void func_short(short x1, short x2)
51{
52	printf("short: %hd %hd\n", x1, x2);
53}
54
55void func_ushort(unsigned short x1, unsigned short x2)
56{
57	printf("ushort: %hu %hu\n", x1, x2);
58}
59
60float func_float(float f1, float f2)
61{
62	printf("%f %f\n", f1, f2);
63	return f1;
64}
65
66double func_double(double f1, double f2)
67{
68	printf("%f %f\n", f1, f2);
69	return f2;
70}
71
72void func_typedef(int x)
73{
74	printf("typedef'd enum: %d\n", x);
75}
76
77void func_arrayi(int* a, int N)
78{
79    int i;
80    printf("array[int]: ");
81    for (i = 0; i < N; i++)
82	printf("%d ", a[i]);
83    printf("\n");
84}
85
86void func_arrayf(float* a, int N)
87{
88    int i;
89    printf("array[float]: ");
90    for (i = 0; i < N; i++)
91	printf("%f ", a[i]);
92    printf("\n");
93}
94
95struct test_struct {
96    int simple;
97    int alen;
98    int slen;
99    struct { int a; int b; }* array;
100    struct { int a; int b; } seq[3];
101    char* str;
102    char* outer_str;
103};
104
105void func_struct(struct test_struct* x)
106{
107    char buf[100];
108    int i;
109
110    printf("struct: ");
111
112    printf("%d, [", x->simple);
113    for (i = 0; i < x->alen; i++) {
114	printf("%d/%d", x->array[i].a, x->array[i].b);
115	if (i < x->alen - 1)
116	    printf(" ");
117    }
118    printf("] [");
119    for (i = 0; i < 3; i++) {
120	printf("%d/%d", x->seq[i].a, x->seq[i].b);
121	if (i < 2)
122	    printf(" ");
123    }
124    printf("] ");
125
126    strncpy(buf, x->str, x->slen);
127    buf[x->slen] = '\0';
128    printf("%s\n", buf);
129}
130
131void func_work (char *x)
132{
133  *x = 'x';
134}
135
136void func_call (char *x, char* y, void (*cb) (char *))
137{
138  cb (y);
139  *x = (*y)++;
140}
141
142struct S2 {
143	float f;
144	char a;
145	char b;
146};
147
148struct S3 {
149	char a[6];
150	float f;
151};
152
153struct S2
154func_struct_2(int i, struct S3 s3, double d)
155{
156	return (struct S2){ s3.f, s3.a[1], s3.a[2] };
157}
158
159struct S4 {
160	long a;
161	long b;
162	long c;
163	long d;
164};
165
166struct S4
167func_struct_large(struct S4 a, struct S4 b)
168{
169	return (struct S4){ a.a + b.a, a.b + b.b, a.c + b.c, a.d + b.d };
170}
171
172struct S5 {
173	char a;
174	char b;
175	long c;
176	long d;
177};
178
179struct S5
180func_struct_large2(struct S5 a, struct S5 b)
181{
182	return (struct S5){ a.a + b.a, a.b + b.b, a.c + b.c, a.d + b.d };
183}
184
185struct S6 {
186	long a;
187	long b;
188	char c;
189	char d;
190};
191
192struct S6
193func_struct_large3(struct S6 a, struct S6 b)
194{
195	return (struct S6){ a.a + b.a, a.b + b.b, a.c + b.c, a.d + b.d };
196}
197
198void
199func_many_args(int a, int b, long c, double d, char e, int f, float g, char h,
200	       int i, double j, int k, double l, char m, int n, short o, int p,
201	       char q, float r, float s, double t, long u, float v, float w,
202	       float x, float y)
203{
204}
205
206void
207func_lens(int a, long b, short c, long d)
208{
209}
210
211int
212func_bool(int a, int b)
213{
214	return !b;
215}
216
217void
218func_hide(int a, int b, int c, int d, int e, int f)
219{
220}
221
222void
223func_charp_string(char *p)
224{
225}
226