home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume26 / unproto / part01 / example.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-07  |  2.0 KB  |  141 lines

  1.  /*
  2.   * @(#) example.c 1.2 91/09/22 21:21:45
  3.   * 
  4.   * Examples of things that can be done with the unproto package
  5.   */
  6.  
  7.  /*
  8.   * New-style argument list with structured argument, one field being pointer
  9.   * to function returning pointer to function with function-pointer argument
  10.   */
  11.  
  12. x(struct {
  13.     struct {
  14.     int (*(*foo) (int (*arg1) (double))) (float arg2);
  15.     } foo;
  16. } baz) {
  17.     return (0);
  18. }
  19.  
  20.  /*
  21.   * Old-style argument list with new-style argument type, declaration
  22.   * embedded within block. Plus a couple assignments with function calls that
  23.   * look like casts.
  24.   */
  25.  
  26. foo(bar)
  27. int     (*(*bar) (float)) (int);
  28. {
  29.     int     (*baz) (int) = (int (*) (int)) 0,
  30.         y = (y * (*baz) (y)),
  31.         *(*z) (int) = (int *(*) (int)) 0;
  32.  
  33.     struct { int (*foo)(int); } *(*s)(int) = 
  34.     (struct { int (*foo)(int); } *(*)(int)) 0;
  35.  
  36.     {
  37.     y = (y * (*baz) (y));
  38.     }
  39.     {
  40.     z = (int *(*) (int)) 0;
  41.     }
  42.     {
  43.     s = (struct { int (*foo)(int); } *(*)(int)) 0;
  44.     }
  45.  
  46.     return (0);
  47. }
  48.  
  49. /* Multiple declarations in one statement */
  50.  
  51. test1()
  52. {
  53.     int foo2,*(*(*bar)(int))(float),*baz(double);
  54. }
  55.  
  56. /* Discriminate declarations from executable statements */
  57.  
  58. test2(char *y)
  59. {
  60.     int foo = 5,atoi(char *);
  61.  
  62.     foo = 5,atoi(y);
  63. }
  64.  
  65. /* Declarations without explicit type */
  66.  
  67. test3,test4(int);
  68.  
  69. test5(int y)
  70. {
  71.     {
  72.         test3;
  73.     }
  74.     {
  75.         test4(y);
  76.     }
  77. }
  78.  
  79. test6[1],test7(int);
  80.  
  81. test7(int x)
  82. {
  83.     {
  84.         test6[1];
  85.     }
  86.     {
  87.         test7(x);
  88.     }
  89. }
  90.  
  91. /* Checking a complicated cast */
  92.  
  93. struct {
  94.     struct {
  95.     int (*f)(int), o;
  96.     } bar;
  97. } (*baz2)(int) = (struct { struct { int (*f)(int), o; } bar; } (*)(int)) 0;
  98.  
  99. /* Distinguish things with the same shape but with different meaning */
  100.  
  101. test8(x)
  102. {
  103.     {
  104.     struct {
  105.         int     foo;
  106.     } bar(int);
  107.     }
  108.     {
  109.     do {
  110.         int     foo;
  111.     } while (x);
  112.     }
  113. }
  114.  
  115. /* Do not think foo(*bar) is a function pointer declaration */
  116.  
  117. test9(char *bar)
  118. {
  119.     foo(*bar);
  120. }
  121.  
  122. /* another couple of special-cased words. */
  123.  
  124. test10(int x)
  125. {
  126.     {
  127.     int test10(int);
  128.     do  test10(x);
  129.     while (x);
  130.     }
  131.     {
  132.     return test10(x);
  133.     }
  134. }
  135.  
  136. test11(int *x)
  137. {
  138.     while (*x)
  139.         (putchar(*x++));
  140. }
  141.