diff options
Diffstat (limited to 'unproto/example.c')
-rw-r--r-- | unproto/example.c | 96 |
1 files changed, 89 insertions, 7 deletions
diff --git a/unproto/example.c b/unproto/example.c index 003df4a..bf2f838 100644 --- a/unproto/example.c +++ b/unproto/example.c @@ -1,9 +1,11 @@ /* - * @(#) example.c 1.2 91/09/22 21:21:45 + * @(#) example.c 1.5 93/06/18 22:29:46 * * Examples of things that can be done with the unproto package */ +typedef char *charstar; + /* * New-style argument list with structured argument, one field being pointer * to function returning pointer to function with function-pointer argument @@ -17,14 +19,23 @@ x(struct { return (0); } + /* New-style function-pointer declaration. */ + +int (*(*bar0) (float)) (int); + + /* Old-style argument list with new-style argument type. */ + +baz0(bar) +int (*(*bar) (float)) (int); +{} + /* - * Old-style argument list with new-style argument type, declaration + * New-style argument list with new-style argument type, declaration * embedded within block. Plus a couple assignments with function calls that * look like casts. */ -foo(bar) -int (*(*bar) (float)) (int); +foo(int (*(*bar) (float)) (int)) { int (*baz) (int) = (int (*) (int)) 0, y = (y * (*baz) (y)), @@ -55,9 +66,9 @@ test1() /* Discriminate declarations from executable statements */ -test2(char *y) +test2(charstar y) { - int foo = 5,atoi(char *); + int foo = 5,atoi(charstar); foo = 5,atoi(y); } @@ -103,7 +114,7 @@ test8(x) { struct { int foo; - } bar(int); + } bar(charstar); } { do { @@ -138,3 +149,74 @@ test11(int *x) while (*x) (putchar(*x++)); } + +test11a(int *x) +{ + for (*x;;) + (putchar(*x++)); +} + +/* #include directive between stuff that requires lookahead */ + +test12() +{ + char *x = "\xf\0002\002\02\2" /* foo */ +#include "/dev/null" + "\abar"; + + printf("foo" /* 1 */ "bar" /* 2 */ "baz"); + + *x = '\a'; + *x = '\xff'; +} + +int test13(void); + +/* line continuations in the middle of tokens */ + +te\ +st14(); +charstar test15 = "foo\ +bar"; +char test16 = "foo\\ +abar"; + +/* Array dimensions with unexpanded macros */ + +test17(charstar foo[bar]){} + +int (*(*test18[bar])(charstar))(charstar) = \ + (int (*(*[bar])(charstar))(charstar)) 0; + +/* Function returning pointer to function */ + +int (*(*test19(long))(int))(double); + +/* GCC accepts the following stuff, K&R C does not... */ + +void test20(int test21(double)) {} + +void test22(struct { int foo; } test23(short)) {} + +/* Do not blindly rewrite (*name(stuff))(otherstuff) */ + +void test23() +{ + int (*test24(int)) (int), + y = (*test24(2)) (3), + z = ((*test24(2)) (3)); +} + +/* Function returning pointer to function */ + +int (*(*test25(long foo))(int bar))(double baz){ /* body */ } + +int (*(*test26(foo))())() +long foo; +{ /* body */ } + +#define ARGSTR() struct {int l; char c[1];} + +void functie(ARGSTR() *cmdlin, ARGSTR() *c1) +{ +} |