home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 355_03 / slk3.exe / TEST / DCLTEST2.C < prev    next >
C/C++ Source or Header  |  1989-06-28  |  4KB  |  200 lines

  1. /*    Construction not handled well by Turbo C 1.5.
  2.  
  3.     source:  dcltest2.c
  4.     version: February 15, 1989
  5. */
  6.  
  7. int f11(b,a,c)
  8. #include "\test\tt\defs2"
  9. struct defs a;
  10. int b,c;
  11. {
  12.     return 1;
  13. }
  14.  
  15. typedef int A[2][3];
  16. float fa[11];
  17. typedef struct s1 {int x;} t1, *tp1;
  18. noalias int a;
  19. struct s;
  20. struct s {int mem;} = {1};
  21.  
  22. /*
  23.     Page 59 of the Rationale of the Draft C Standard says that the
  24.     argument list of a function must be explicitly present, i.e., it can
  25.     not be inherited from a typedef. Thus, the following is    invalid:
  26.  
  27.     typedef int F(void);
  28.     F g {}
  29. */
  30.  
  31. typedef int F(void);
  32. F f,g;
  33. F g () {}
  34. F *e(void) {}
  35. F *Fp;
  36.  
  37. const struct s3 {int mem; } = {1};
  38. const int *ptr_to_constant;
  39. int *const constant_ptr;
  40. extern const volatile int real_time_clock;
  41. const A a2  = {{4,5,6},{7,8,9}};
  42.  
  43.  
  44. /*
  45.     Tests of SPP's macro handling abilities.
  46.  
  47.     source: macro.tst
  48.     version: February 17, 1989
  49. */
  50.  
  51. /*
  52.     PART I
  53.  
  54.     Weird and wonderful tests of macro expansion.
  55.     see page 93 of Draft C Standard of January, 1988.
  56. */
  57. #define x 3
  58. #define f(a) f(x * (a))
  59. #undef x
  60.  
  61. #define x 2
  62. #define g f
  63. #define z z[0]
  64. #define h g(~
  65. #define m(a) a(w)
  66. #define w 0,1
  67. #define t(a) a
  68.  
  69. macro_tst()
  70. {
  71.  
  72. SL_DISABLE();
  73.  
  74. /* subtest 1
  75. f(y+1); should expand to:
  76. f(2 * (y+1));
  77. */
  78. f(y+1);
  79.  
  80. /* subtest 2
  81. f(f(z)); should expand to:
  82. f(2 * (f(2 * (z[0]))));
  83. */
  84. f(f(z));
  85.  
  86. /* subtest 3
  87. t(t(g)(0) + t)(1); should expand to:
  88. f(2 * (0)) + t(1);
  89. */
  90. t(t(g)(0) + t)(1);
  91.  
  92. /* subtest 4
  93. g(x+(3,4)-w) | h 5) & m (f)^m(m);
  94. should result in:
  95. f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
  96. */
  97. g(x+(3,4)-w) | h 5) & m (f)^m(m);
  98.  
  99. }
  100.  
  101.  
  102. /*
  103.     PART 2
  104.     Tests of string concatenation and token pasting.
  105. */
  106. #define str(s) # s
  107. #define xstr(s) str(s)
  108. #define debug(s,t) printf("x" # s "= %d, x" # t "= %s", x ## s, x ## t)
  109.  
  110. stringize()
  111. {
  112.  
  113. SL_DISABLE();
  114.  
  115. /*
  116. #define str(s) # s
  117. #define xstr(s) str(s)
  118. #define debug(s,t) printf("x" # s "= %d, x" # t "= %s", x ## s, x ## t)
  119. debug(1, 2);
  120.  
  121. should result in:
  122. printf("x1= %d, x2= %s", x1, x2);
  123. */
  124. debug(1, 2);
  125.  
  126. /*
  127. fputs(str(strncmp("abc\0d", "abc", '\4') == 0) str(: @\n), s);
  128. should result in:
  129. fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0: @\n", s);
  130. */
  131. fputs(str(strncmp("abc\0d", "abc", '\4') == 0) str(: @\n), s);
  132.  
  133. }
  134.  
  135. /*
  136.     PART 3
  137.     Tests of detecting duplicate definitions
  138.  
  139.     These examples do not follow the standard yet.
  140.     Please do not report these as bugs to me.
  141. */
  142. #ifdef NOT_YET
  143. #define OBJ_LIKE (1-1)
  144. #define OBJ_LIKE /* a */  (1-1) /* b */
  145. #define FTN_LIKE(a) ( a )
  146. #define FTN_LIKE( a ) ( /* a */ \
  147.     a  /* b
  148.     */ )
  149.  
  150.  
  151. #define OBJ_LIKE (0)
  152. #define OBJ_LIKE (1 - 1)
  153. #define FTN_LIKE(b) ( a )
  154. #define FTN_LIKE(b) (b)
  155. #endif
  156.  
  157. /*    PART 4
  158.     Bug regression test:
  159.  
  160.     Test for white space in argument list in macros.
  161.  
  162.     Test for more than six arguments.
  163.  
  164.     Test for recursive definition of keywords
  165. */
  166.  
  167. #define char (signed) char
  168. char c;
  169.  
  170. #pragma this can be anything
  171.  
  172. #pragma ##who cares##??
  173.  
  174. /* Test of defined keyword. */
  175. #if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
  176. #define TINY_OR_SMALL_OR_MEDIUM
  177. #endif
  178.  
  179. /*
  180.     Test line number handling.
  181.     Note: #error will terminate the processing of this test file.
  182. */
  183. #define FILE_NAME "d:\sherlock\sl.h"
  184. #define LINE2 1000
  185. #define FILE2 "changed_file"
  186. #include FILE_NAME
  187. #line LINE2 FILE2
  188.  
  189. #define a( b , c , d , e , f , g , h ) b c d e f g h
  190.  
  191. line_number_test()
  192. {
  193.     int b;
  194.  
  195.     SL_DISABLE();
  196.  
  197.     a(b, = , 1, + , 2, - , 3);
  198.  
  199. }
  200.