2 * @(#) example.c 1.5 93/06/18 22:29:46
4 * Examples of things that can be done with the unproto package
7 typedef char *charstar;
10 * New-style argument list with structured argument, one field being pointer
11 * to function returning pointer to function with function-pointer argument
16 int (*(*foo) (int (*arg1) (double))) (float arg2);
22 /* New-style function-pointer declaration. */
24 int (*(*bar0) (float)) (int);
26 /* Old-style argument list with new-style argument type. */
29 int (*(*bar) (float)) (int);
33 * New-style argument list with new-style argument type, declaration
34 * embedded within block. Plus a couple assignments with function calls that
38 foo(int (*(*bar) (float)) (int))
40 int (*baz) (int) = (int (*) (int)) 0,
42 *(*z) (int) = (int *(*) (int)) 0;
44 struct { int (*foo)(int); } *(*s)(int) =
45 (struct { int (*foo)(int); } *(*)(int)) 0;
51 z = (int *(*) (int)) 0;
54 s = (struct { int (*foo)(int); } *(*)(int)) 0;
60 /* Multiple declarations in one statement */
64 int foo2,*(*(*bar)(int))(float),*baz(double);
67 /* Discriminate declarations from executable statements */
71 int foo = 5,atoi(charstar);
76 /* Declarations without explicit type */
102 /* Checking a complicated cast */
108 } (*baz2)(int) = (struct { struct { int (*f)(int), o; } bar; } (*)(int)) 0;
110 /* Distinguish things with the same shape but with different meaning */
126 /* Do not think foo(*bar) is a function pointer declaration */
133 /* another couple of special-cased words. */
159 /* #include directive between stuff that requires lookahead */
163 char *x = "\xf\0002\002\02\2" /* foo */
167 printf("foo" /* 1 */ "bar" /* 2 */ "baz");
175 /* line continuations in the middle of tokens */
179 charstar test15 = "foo\
184 /* Array dimensions with unexpanded macros */
186 test17(charstar foo[bar]){}
188 int (*(*test18[bar])(charstar))(charstar) = \
189 (int (*(*[bar])(charstar))(charstar)) 0;
191 /* Function returning pointer to function */
193 int (*(*test19(long))(int))(double);
195 /* GCC accepts the following stuff, K&R C does not... */
197 void test20(int test21(double)) {}
199 void test22(struct { int foo; } test23(short)) {}
201 /* Do not blindly rewrite (*name(stuff))(otherstuff) */
205 int (*test24(int)) (int),
206 y = (*test24(2)) (3),
207 z = ((*test24(2)) (3));
210 /* Function returning pointer to function */
212 int (*(*test25(long foo))(int bar))(double baz){ /* body */ }
214 int (*(*test26(foo))())()
218 #define ARGSTR() struct {int l; char c[1];}
220 void functie(ARGSTR() *cmdlin, ARGSTR() *c1)