parameters-lib.c revision 280f829ca87ff6b6c3a242a97fcef01d4488d2c8
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_ppp(int*** ppp)
31{
32	printf("%d\n", ***ppp);
33}
34
35void func_stringp(char** sP)
36{
37	printf("%s\n", *sP);
38}
39
40void func_enum(int x)
41{
42	printf("enum: %d\n", x);
43}
44
45void func_short(short x1, short x2)
46{
47	printf("short: %hd %hd\n", x1, x2);
48}
49
50void func_ushort(unsigned short x1, unsigned short x2)
51{
52	printf("ushort: %hu %hu\n", x1, x2);
53}
54
55float func_float(float f1, float f2)
56{
57	printf("%f %f\n", f1, f2);
58	return f1;
59}
60
61double func_double(double f1, double f2)
62{
63	printf("%f %f\n", f1, f2);
64	return f2;
65}
66
67void func_typedef(int x)
68{
69	printf("typedef'd enum: %d\n", x);
70}
71
72void func_arrayi(int* a, int N)
73{
74    int i;
75    printf("array[int]: ");
76    for (i = 0; i < N; i++)
77	printf("%d ", a[i]);
78    printf("\n");
79}
80
81void func_arrayf(float* a, int N)
82{
83    int i;
84    printf("array[float]: ");
85    for (i = 0; i < N; i++)
86	printf("%f ", a[i]);
87    printf("\n");
88}
89
90struct test_struct {
91    int simple;
92    int alen;
93    int slen;
94    struct { int a; int b; }* array;
95    struct { int a; int b; } seq[3];
96    char* str;
97    char* outer_str;
98};
99
100void func_struct(struct test_struct* x)
101{
102    char buf[100];
103    int i;
104
105    printf("struct: ");
106
107    printf("%d, [", x->simple);
108    for (i = 0; i < x->alen; i++) {
109	printf("%d/%d", x->array[i].a, x->array[i].b);
110	if (i < x->alen - 1)
111	    printf(" ");
112    }
113    printf("] [");
114    for (i = 0; i < 3; i++) {
115	printf("%d/%d", x->seq[i].a, x->seq[i].b);
116	if (i < 2)
117	    printf(" ");
118    }
119    printf("] ");
120
121    strncpy(buf, x->str, x->slen);
122    buf[x->slen] = '\0';
123    printf("%s\n", buf);
124}
125
126void func_work (char *x)
127{
128  *x = 'x';
129}
130
131void func_call (char *x, char* y, void (*cb) (char *))
132{
133  cb (y);
134  *x = (*y)++;
135}
136