1 #include <string.h>
2 #include <stdio.h>
3
func_ignore(int a,int b,int c)4 void func_ignore(int a, int b, int c)
5 {
6 printf("%d\n", a + b + c);
7 }
8
func_intptr(int * i)9 void func_intptr(int *i)
10 {
11 printf("%d\n", *i);
12 }
13
func_intptr_ret(int * i)14 void func_intptr_ret(int *i)
15 {
16 *i = 42;
17 }
18
func_strlen(char * p)19 int func_strlen(char* p)
20 {
21 strcpy(p, "Hello world");
22 return strlen(p);
23 }
24
func_arg0(char * p)25 int func_arg0(char *p)
26 {
27 strcpy(p, "Hello another world!");
28 return strlen(p);
29 }
30
func_strfixed(char * p)31 void func_strfixed(char* p)
32 {
33 strcpy(p, "Hello world");
34 }
35
func_string(char * p)36 void func_string(char* p)
37 {
38 printf("%s\n", p);
39 }
40
func_ppp(int *** ppp)41 void func_ppp(int*** ppp)
42 {
43 printf("%d\n", ***ppp);
44 }
45
func_stringp(char ** sP)46 void func_stringp(char** sP)
47 {
48 printf("%s\n", *sP);
49 }
50
func_enum(int x)51 void func_enum(int x)
52 {
53 printf("enum: %d\n", x);
54 }
55
func_short(short x1,short x2)56 void func_short(short x1, short x2)
57 {
58 printf("short: %hd %hd\n", x1, x2);
59 }
60
func_ushort(unsigned short x1,unsigned short x2)61 void func_ushort(unsigned short x1, unsigned short x2)
62 {
63 printf("ushort: %hu %hu\n", x1, x2);
64 }
65
func_float(float f1,float f2)66 float func_float(float f1, float f2)
67 {
68 printf("%f %f\n", f1, f2);
69 return f1;
70 }
71
func_double(double f1,double f2)72 double func_double(double f1, double f2)
73 {
74 printf("%f %f\n", f1, f2);
75 return f2;
76 }
77
func_typedef(int x)78 void func_typedef(int x)
79 {
80 printf("typedef'd enum: %d\n", x);
81 }
82
func_arrayi(int * a,int N)83 void func_arrayi(int* a, int N)
84 {
85 int i;
86 printf("array[int]: ");
87 for (i = 0; i < N; i++)
88 printf("%d ", a[i]);
89 printf("\n");
90 }
91
func_arrayf(float * a,int N)92 void func_arrayf(float* a, int N)
93 {
94 int i;
95 printf("array[float]: ");
96 for (i = 0; i < N; i++)
97 printf("%f ", a[i]);
98 printf("\n");
99 }
100
101 struct test_struct {
102 int simple;
103 int alen;
104 int slen;
105 struct { int a; int b; }* array;
106 struct { int a; int b; } seq[3];
107 char* str;
108 char* outer_str;
109 };
110
func_struct(struct test_struct * x)111 void func_struct(struct test_struct* x)
112 {
113 char buf[100];
114 int i;
115
116 printf("struct: ");
117
118 printf("%d, [", x->simple);
119 for (i = 0; i < x->alen; i++) {
120 printf("%d/%d", x->array[i].a, x->array[i].b);
121 if (i < x->alen - 1)
122 printf(" ");
123 }
124 printf("] [");
125 for (i = 0; i < 3; i++) {
126 printf("%d/%d", x->seq[i].a, x->seq[i].b);
127 if (i < 2)
128 printf(" ");
129 }
130 printf("] ");
131
132 strncpy(buf, x->str, x->slen);
133 buf[x->slen] = '\0';
134 printf("%s\n", buf);
135 }
136
func_work(char * x)137 void func_work (char *x)
138 {
139 *x = 'x';
140 }
141
func_call(char * x,char * y,void (* cb)(char *))142 void func_call (char *x, char* y, void (*cb) (char *))
143 {
144 cb (y);
145 *x = (*y)++;
146 }
147
148 struct S2 {
149 float f;
150 char a;
151 char b;
152 };
153
154 struct S3 {
155 char a[6];
156 float f;
157 };
158
159 struct S2
func_struct_2(int i,struct S3 s3,double d)160 func_struct_2(int i, struct S3 s3, double d)
161 {
162 return (struct S2){ s3.f, s3.a[1], s3.a[2] };
163 }
164
165 struct S4 {
166 long a;
167 long b;
168 long c;
169 long d;
170 };
171
172 struct S4
func_struct_large(struct S4 a,struct S4 b)173 func_struct_large(struct S4 a, struct S4 b)
174 {
175 return (struct S4){ a.a + b.a, a.b + b.b, a.c + b.c, a.d + b.d };
176 }
177
178 struct S5 {
179 char a;
180 char b;
181 long c;
182 long d;
183 };
184
185 struct S5
func_struct_large2(struct S5 a,struct S5 b)186 func_struct_large2(struct S5 a, struct S5 b)
187 {
188 return (struct S5){ a.a + b.a, a.b + b.b, a.c + b.c, a.d + b.d };
189 }
190
191 struct S6 {
192 long a;
193 long b;
194 char c;
195 char d;
196 };
197
198 struct S6
func_struct_large3(struct S6 a,struct S6 b)199 func_struct_large3(struct S6 a, struct S6 b)
200 {
201 return (struct S6){ a.a + b.a, a.b + b.b, a.c + b.c, a.d + b.d };
202 }
203
204 void
func_many_args(int a,int b,long c,double d,char e,int f,float g,char h,int i,double j,int k,double l,char m,int n,short o,int p,char q,float r,float s,double t,long u,float v,float w,float x,float y)205 func_many_args(int a, int b, long c, double d, char e, int f, float g, char h,
206 int i, double j, int k, double l, char m, int n, short o, int p,
207 char q, float r, float s, double t, long u, float v, float w,
208 float x, float y)
209 {
210 }
211
212 void
func_lens(int a,long b,short c,long d)213 func_lens(int a, long b, short c, long d)
214 {
215 }
216
217 int
func_bool(int a,int b)218 func_bool(int a, int b)
219 {
220 return !b;
221 }
222
223 void
func_hide(int a,int b,int c,int d,int e,int f)224 func_hide(int a, int b, int c, int d, int e, int f)
225 {
226 }
227
228 struct func_hide_struct {
229 int a; int b; int c; int d; int e; int f; int g; int h;
230 };
231
232 void
func_hide_struct(struct func_hide_struct s)233 func_hide_struct(struct func_hide_struct s)
234 {
235 }
236
237 long *
func_short_enums(short values[])238 func_short_enums(short values[])
239 {
240 static long retvals[4];
241 retvals[0] = values[0];
242 retvals[1] = values[1];
243 retvals[2] = values[2];
244 retvals[3] = values[3];
245 return retvals;
246 }
247
248 long
func_negative_enum(short a,unsigned short b,int c,unsigned d,long e,unsigned long f)249 func_negative_enum(short a, unsigned short b, int c, unsigned d,
250 long e, unsigned long f)
251 {
252 return -1;
253 }
254
255 void
func_charp_string(char * p)256 func_charp_string(char *p)
257 {
258 }
259
260 struct struct_empty {};
261 struct struct_size1 { char a; };
262 struct struct_size2 { short a; };
263 struct struct_size4 { int a; };
264 struct struct_size8 { int a; int b; };
265
266 struct struct_empty
func_struct_empty(struct struct_empty e)267 func_struct_empty(struct struct_empty e)
268 {
269 return e;
270 }
271
272 struct struct_size1
func_struct_size1(struct struct_size1 e)273 func_struct_size1(struct struct_size1 e)
274 {
275 return e;
276 }
277
278 struct struct_size2
func_struct_size2(struct struct_size2 e)279 func_struct_size2(struct struct_size2 e)
280 {
281 return e;
282 }
283
284 struct struct_size4
func_struct_size4(struct struct_size4 e)285 func_struct_size4(struct struct_size4 e)
286 {
287 return e;
288 }
289
290 struct struct_size8
func_struct_size8(struct struct_size8 e)291 func_struct_size8(struct struct_size8 e)
292 {
293 return e;
294 }
295
296 void
func_printf(char * format,...)297 func_printf(char *format, ...)
298 {
299 }
300
301 void
func_sprintf(char * str,char * format,...)302 func_sprintf(char *str, char *format, ...)
303 {
304 }
305