home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gdb-4.9 / gdb / testsuite / gdb.t15 / gdbme.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-12  |  9.0 KB  |  389 lines

  1. /*  Test passing of arguments to functions.  Use various sorts of arguments,
  2.     including basic types, pointers to those types, structures, lots of
  3.     args, etc, in various combinations. */
  4.  
  5.  
  6. char c = 'a';
  7. char *cp = &c;
  8.  
  9. unsigned char uc = 'b';
  10. unsigned char *ucp = &uc;
  11.  
  12. short s = 1;
  13. short *sp = &s;
  14.  
  15. unsigned short us = 6;
  16. unsigned short *usp = &us;
  17.  
  18. int i = 2;
  19. int *ip = &i;
  20.  
  21. unsigned int ui = 7;
  22. unsigned int *uip = &ui;
  23.  
  24. long l = 3;
  25. long *lp = &l;
  26.  
  27. unsigned long ul = 8;
  28. unsigned long *ulp = &ul;
  29.  
  30. float f = 4.0;
  31. float *fp = &f;
  32.  
  33. double d = 5.0;
  34. double *dp = &d;
  35.  
  36. struct stag {
  37.     int s1;
  38.     int s2;
  39. } st = { 101, 102 };
  40. struct stag *stp = &st;
  41.  
  42. union utag {
  43.     int u1;
  44.     long u2;
  45. } un;
  46. union utag *unp = &un;
  47.  
  48. char carray[] = {'a', 'n', ' ', 'a', 'r', 'r', 'a', 'y', '\0'};
  49.  
  50.  
  51. /* Test various permutations and interleaving of integral arguments */
  52.  
  53.  
  54. call0a (c, s, i, l)
  55. char c; short s; int i; long l; {}
  56.  
  57. call0b (s, i, l, c)
  58. short s; int i; long l; char c; {}
  59.  
  60. call0c (i, l, c, s)
  61. int i; long l; char c; short s; {}
  62.  
  63. call0d (l, c, s, i)
  64. long l; char c; short s; int i; {}
  65.  
  66. call0e (c1, l, c2, i, c3, s, c4, c5)
  67. char c1; long l; char c2; int i; char c3; short s; char c4; char c5; {}
  68.  
  69.  
  70. /* Test various permutations and interleaving of unsigned integral arguments */
  71.  
  72.  
  73. call1a (uc, us, ui, ul)
  74. unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul; {}
  75.  
  76. call1b (us, ui, ul, uc)
  77. unsigned short us; unsigned int ui; unsigned long ul; unsigned char uc; {}
  78.  
  79. call1c (ui, ul, uc, us)
  80. unsigned int ui; unsigned long ul; unsigned char uc; unsigned short us; {}
  81.  
  82. call1d (ul, uc, us, ui)
  83. unsigned long ul; unsigned char uc; unsigned short us; unsigned int ui; {}
  84.  
  85. call1e (uc1, ul, uc2, ui, uc3, us, uc4, uc5)
  86. unsigned char uc1; unsigned long ul; unsigned char uc2; unsigned int ui;
  87. unsigned char uc3; unsigned short us; unsigned char uc4; unsigned char uc5; {}
  88.  
  89.  
  90. /* Test various permutations and interleaving of integral arguments with
  91.    floating point arguments. */
  92.  
  93.  
  94. call2a (c, f1, s, d1, i, f2, l, d2)
  95. char c; float f1; short s; double d1; int i; float f2; long l; double d2; {}
  96.  
  97. call2b (f1, s, d1, i, f2, l, d2, c)
  98. float f1; short s; double d1; int i; float f2; long l; double d2; char c; {}
  99.  
  100. call2c (s, d1, i, f2, l, d2, c, f1)
  101. short s; double d1; int i; float f2; long l; double d2; char c; float f1; {}
  102.  
  103. call2d (d1, i, f2, l, d2, c, f1, s)
  104. double d1; int i; float f2; long l; double d2; char c; float f1; short s; {}
  105.  
  106. call2e (i, f2, l, d2, c, f1, s, d1)
  107. int i; float f2; long l; double d2; char c; float f1; short s; double d1; {}
  108.  
  109. call2f (f2, l, d2, c, f1, s, d1, i)
  110. float f2; long l; double d2; char c; float f1; short s; double d1; int i; {}
  111.  
  112. call2g (l, d2, c, f1, s, d1, i, f2)
  113. long l; double d2; char c; float f1; short s; double d1; int i; float f2; {}
  114.  
  115. call2h (d2, c, f1, s, d1, i, f2, l)
  116. double d2; char c; float f1; short s; double d1; int i; float f2; long l; {}
  117.  
  118. call2i (c1, f1, c2, c3, d1, c4, c5, c6, f2, s, c7, d2)
  119. char c1; float f1; char c2; char c3; double d1; char c4; char c5; char c6;
  120. float f2; short s; char c7; double d2; {}
  121.  
  122.  
  123. /* Test pointers to various integral and floating types. */
  124.  
  125.  
  126. call3a (cp, sp, ip, lp)
  127. char *cp; short *sp; int *ip; long *lp; {}
  128.  
  129. call3b (ucp, usp, uip, ulp)
  130. unsigned char *ucp; unsigned short *usp; unsigned int *uip;
  131. unsigned long *ulp; {}
  132.  
  133. call3c (fp, dp)
  134. float *fp; double *dp; {}
  135.  
  136.  
  137. /* Test passing structures and unions by reference. */
  138.  
  139.  
  140. call4a (stp)
  141. struct stag *stp; {}
  142.  
  143. call4b (unp)
  144. union utag *unp; {}
  145.  
  146.  
  147. /* Test passing structures and unions by value. */
  148.  
  149.  
  150. call5a (st)
  151. struct stag st; {}
  152.  
  153. call5b (un)
  154. union utag un; {}
  155.  
  156.  
  157. /* Test shuffling of args */
  158.  
  159.  
  160. call6a (c, s, i, l, f, d, uc, us, ui, ul)
  161. char c; short s; int i; long l; float f; double d;
  162. unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
  163. {
  164.     call6b (s, i, l, f, d, uc, us, ui, ul);
  165. }
  166.  
  167. call6b (s, i, l, f, d, uc, us, ui, ul)
  168. short s; int i; long l; float f; double d;
  169. unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
  170. {
  171.     call6c (i, l, f, d, uc, us, ui, ul);
  172. }
  173.  
  174. call6c (i, l, f, d, uc, us, ui, ul)
  175. int i; long l; float f; double d;
  176. unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
  177. {
  178.     call6d (l, f, d, uc, us, ui, ul);
  179. }
  180.  
  181. call6d (l, f, d, uc, us, ui, ul)
  182. long l; float f; double d;
  183. unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
  184. {
  185.     call6e (f, d, uc, us, ui, ul);
  186. }
  187.  
  188. call6e (f, d, uc, us, ui, ul)
  189. float f; double d;
  190. unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
  191. {
  192.     call6f (d, uc, us, ui, ul);
  193. }
  194.  
  195. call6f (d, uc, us, ui, ul)
  196. double d;
  197. unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
  198. {
  199.     call6g (uc, us, ui, ul);
  200. }
  201.  
  202. call6g (uc, us, ui, ul)
  203. unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
  204. {
  205.     call6h (us, ui, ul);
  206. }
  207.  
  208. call6h (us, ui, ul)
  209. unsigned short us; unsigned int ui; unsigned long ul;
  210. {
  211.     call6i (ui, ul);
  212. }
  213.  
  214. call6i (ui, ul)
  215. unsigned int ui; unsigned long ul;
  216. {
  217.     call6j (ul);
  218. }
  219.  
  220. call6j (ul)
  221. unsigned long ul;
  222. {
  223.     call6k ();
  224. }
  225.  
  226. call6k ()
  227. {
  228. }
  229.  
  230.  
  231. /*  Test shuffling of args, round robin */
  232.  
  233.  
  234. call7a (c, i, s, l, f, uc, d, us, ul, ui)
  235. char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui;
  236. {
  237.     call7b (i, s, l, f, uc, d, us, ul, ui, c);
  238. }
  239.  
  240. call7b (i, s, l, f, uc, d, us, ul, ui, c)
  241. int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c;
  242. {
  243.     call7c (s, l, f, uc, d, us, ul, ui, c, i);
  244. }
  245.  
  246. call7c (s, l, f, uc, d, us, ul, ui, c, i)
  247. short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i;
  248. {
  249.     call7d (l, f, uc, d, us, ul, ui, c, i, s);
  250. }
  251.  
  252. call7d (l, f, uc, d, us, ul, ui, c, i, s)
  253. long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s;
  254. {
  255.     call7e (f, uc, d, us, ul, ui, c, i, s, l);
  256. }
  257.  
  258. call7e (f, uc, d, us, ul, ui, c, i, s, l)
  259. float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l;
  260. {
  261.     call7f (uc, d, us, ul, ui, c, i, s, l, f);
  262. }
  263.  
  264. call7f (uc, d, us, ul, ui, c, i, s, l, f)
  265. unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f;
  266. {
  267.     call7g (d, us, ul, ui, c, i, s, l, f, uc);
  268. }
  269.  
  270. call7g (d, us, ul, ui, c, i, s, l, f, uc)
  271. double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc;
  272. {
  273.     call7h (us, ul, ui, c, i, s, l, f, uc, d);
  274. }
  275.  
  276. call7h (us, ul, ui, c, i, s, l, f, uc, d)
  277. unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d;
  278. {
  279.     call7i (ul, ui, c, i, s, l, f, uc, d, us);
  280. }
  281.  
  282. call7i (ul, ui, c, i, s, l, f, uc, d, us)
  283. unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us;
  284. {
  285.     call7j (ui, c, i, s, l, f, uc, d, us, ul);
  286. }
  287.  
  288. call7j (ui, c, i, s, l, f, uc, d, us, ul)
  289. unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul;
  290. {
  291.     call7k (c, i, s, l, f, uc, d, us, ul, ui);
  292. }
  293.  
  294. call7k (c, i, s, l, f, uc, d, us, ul, ui)
  295. char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui;
  296. {
  297. }
  298.  
  299.  
  300. /*  Test printing of structures passed as arguments to recursive functions. */
  301.  
  302.  
  303. typedef struct s
  304. {
  305.   short s;
  306.   int i;
  307.   long l;
  308. } SVAL;    
  309.  
  310. hitbottom ()
  311. {
  312. }
  313.  
  314. void recurse (a, depth)
  315. SVAL a;
  316. int depth;
  317. {
  318.   a.s = a.i = a.l = --depth;
  319.   if (depth == 0)
  320.     hitbottom ();
  321.   else
  322.     recurse (a, depth);
  323. }
  324.  
  325. test_struct_args ()
  326. {
  327.   SVAL s; s.s = 5; s.i = 5; s.l = 5;
  328.  
  329.   recurse (s, 5);
  330. }
  331.  
  332. /*======================================================================*/
  333.  
  334. main ()
  335. {
  336.   /* Test calling with basic integer types */
  337.   call0a (c, s, i, l);
  338.   call0b (s, i, l, c);
  339.   call0c (i, l, c, s);
  340.   call0d (l, c, s, i);
  341.   call0e (c, l, c, i, c, s, c, c);
  342.  
  343.   /* Test calling with unsigned integer types */
  344.   call1a (uc, us, ui, ul);
  345.   call1b (us, ui, ul, uc);
  346.   call1c (ui, ul, uc, us);
  347.   call1d (ul, uc, us, ui);
  348.   call1e (uc, ul, uc, ui, uc, us, uc, uc);
  349.  
  350.   /* Test calling with integral types mixed with floating point types */
  351.   call2a (c, f, s, d, i, f, l, d);
  352.   call2b (f, s, d, i, f, l, d, c);
  353.   call2c (s, d, i, f, l, d, c, f);
  354.   call2d (d, i, f, l, d, c, f, s);
  355.   call2e (i, f, l, d, c, f, s, d);
  356.   call2f (f, l, d, c, f, s, d, i);
  357.   call2g (l, d, c, f, s, d, i, f);
  358.   call2h (d, c, f, s, d, i, f, l);
  359.   call2i (c, f, c, c, d, c, c, c, f, s, c, d);;
  360.  
  361.   /* Test dereferencing pointers to various integral and floating types */
  362.  
  363.   call3a (cp, sp, ip, lp);
  364.   call3b (ucp, usp, uip, ulp);
  365.   call3c (fp, dp);
  366.  
  367.   /* Test dereferencing pointers to structs and unions */
  368.  
  369.   call4a (stp);
  370.   un.u1 = 1;
  371.   call4b (unp);
  372.  
  373.   /* Test calling with structures and unions. */
  374.  
  375.   call5a (st);
  376.   un.u1 = 2;
  377.   call5b (un);
  378.  
  379.   /* Test shuffling of args */
  380.  
  381.   call6a (c, s, i, l, f, d, uc, us, ui, ul);
  382.   call7a (c, i, s, l, f, uc, d, us, ul, ui);
  383.   
  384.   /* Test passing structures recursively. */
  385.  
  386.   test_struct_args ();
  387.  
  388. }
  389.