]> git.sur5r.net Git - openldap/blob - build/unproto/example.c
Check LOCK_ID() return
[openldap] / build / unproto / example.c
1  /*
2   * @(#) example.c 1.5 93/06/18 22:29:46
3   * 
4   * Examples of things that can be done with the unproto package
5   */
6
7 typedef char *charstar;
8
9  /*
10   * New-style argument list with structured argument, one field being pointer
11   * to function returning pointer to function with function-pointer argument
12   */
13
14 x(struct {
15     struct {
16         int (*(*foo) (int (*arg1) (double))) (float arg2);
17     } foo;
18 } baz) {
19     return (0);
20 }
21
22  /* New-style function-pointer declaration. */
23
24 int (*(*bar0) (float)) (int);
25
26  /* Old-style argument list with new-style argument type. */
27
28 baz0(bar)
29 int (*(*bar) (float)) (int);
30 {}
31
32  /*
33   * New-style argument list with new-style argument type, declaration
34   * embedded within block. Plus a couple assignments with function calls that
35   * look like casts.
36   */
37
38 foo(int (*(*bar) (float)) (int))
39 {
40     int     (*baz) (int) = (int (*) (int)) 0,
41             y = (y * (*baz) (y)),
42             *(*z) (int) = (int *(*) (int)) 0;
43
44     struct { int (*foo)(int); } *(*s)(int) = 
45         (struct { int (*foo)(int); } *(*)(int)) 0;
46
47     {
48         y = (y * (*baz) (y));
49     }
50     {
51         z = (int *(*) (int)) 0;
52     }
53     {
54         s = (struct { int (*foo)(int); } *(*)(int)) 0;
55     }
56
57     return (0);
58 }
59
60 /* Multiple declarations in one statement */
61
62 test1()
63 {
64         int foo2,*(*(*bar)(int))(float),*baz(double);
65 }
66
67 /* Discriminate declarations from executable statements */
68
69 test2(charstar y)
70 {
71         int foo = 5,atoi(charstar);
72
73         foo = 5,atoi(y);
74 }
75
76 /* Declarations without explicit type */
77
78 test3,test4(int);
79
80 test5(int y)
81 {
82         {
83                 test3;
84         }
85         {
86                 test4(y);
87         }
88 }
89
90 test6[1],test7(int);
91
92 test7(int x)
93 {
94         {
95                 test6[1];
96         }
97         {
98                 test7(x);
99         }
100 }
101
102 /* Checking a complicated cast */
103
104 struct {
105     struct {
106         int (*f)(int), o;
107     } bar;
108 } (*baz2)(int) = (struct { struct { int (*f)(int), o; } bar; } (*)(int)) 0;
109
110 /* Distinguish things with the same shape but with different meaning */
111
112 test8(x)
113 {
114     {
115         struct {
116             int     foo;
117         } bar(charstar);
118     }
119     {
120         do {
121             int     foo;
122         } while (x);
123     }
124 }
125
126 /* Do not think foo(*bar) is a function pointer declaration */
127
128 test9(char *bar)
129 {
130     foo(*bar);
131 }
132
133 /* another couple of special-cased words. */
134
135 test10(int x)
136 {
137     {
138         int test10(int);
139         do  test10(x);
140         while (x);
141     }
142     {
143         return test10(x);
144     }
145 }
146
147 test11(int *x)
148 {
149         while (*x)
150             (putchar(*x++));
151 }
152
153 test11a(int *x)
154 {
155         for (*x;;)
156             (putchar(*x++));
157 }
158
159 /* #include directive between stuff that requires lookahead */
160
161 test12()
162 {
163         char *x = "\xf\0002\002\02\2" /* foo */
164 #include "/dev/null"
165                 "\abar";
166
167         printf("foo" /* 1 */ "bar" /* 2 */ "baz");
168
169         *x = '\a';
170         *x = '\xff';
171 }
172
173 int test13(void);
174
175 /* line continuations in the middle of tokens */
176
177 te\
178 st14();
179 charstar test15 = "foo\
180 bar";
181 char test16 = "foo\\
182 abar";
183
184 /* Array dimensions with unexpanded macros */
185
186 test17(charstar foo[bar]){}
187
188 int (*(*test18[bar])(charstar))(charstar) = \
189         (int (*(*[bar])(charstar))(charstar)) 0;
190
191 /* Function returning pointer to function */
192
193 int (*(*test19(long))(int))(double);
194
195 /* GCC accepts the following stuff, K&R C does not... */
196
197 void test20(int test21(double)) {}
198
199 void test22(struct { int foo; } test23(short)) {}
200
201 /* Do not blindly rewrite (*name(stuff))(otherstuff) */
202
203 void    test23()
204 {
205     int     (*test24(int)) (int),
206             y = (*test24(2)) (3),
207             z = ((*test24(2)) (3));
208 }
209
210 /* Function returning pointer to function */
211
212 int (*(*test25(long foo))(int bar))(double baz){ /* body */ }
213
214 int (*(*test26(foo))())()
215 long foo;
216 { /* body */ }
217
218 #define ARGSTR()   struct {int l; char c[1];}
219
220 void functie(ARGSTR() *cmdlin, ARGSTR() *c1)
221 {
222 }