GDB: trad-frame: Store length of value_bytes in trad_frame_saved_reg
[binutils-gdb.git] / gdb / testsuite / gdb.base / varargs.c
blobe0083c7d8bd751e76d05c084504f72191754d35b
1 /* varargs.c -
2 * (Added as part of fix for bug 15306 - "call" to varargs functions fails)
3 * This program is intended to let me try out "call" to varargs functions
4 * with varying numbers of declared args and various argument types.
5 * - RT 9/27/95
6 */
8 #include <stdio.h>
9 #include <stdarg.h>
11 #include "unbuffer_output.c"
13 int find_max1(int, ...);
14 int find_max2(int, int, ...);
15 double find_max_double(int, double, ...);
17 char ch;
18 unsigned char uc;
19 short s;
20 unsigned short us;
21 int a,b,c,d;
22 int max_val;
23 long long ll;
24 float fa,fb,fc,fd;
25 double da,db,dc,dd;
26 double dmax_val;
28 #ifdef TEST_COMPLEX
29 extern float crealf (float _Complex);
30 extern double creal (double _Complex);
31 extern long double creall (long double _Complex);
33 float _Complex fc1 = 1.0F + 1.0iF;
34 float _Complex fc2 = 2.0F + 2.0iF;
35 float _Complex fc3 = 3.0F + 3.0iF;
36 float _Complex fc4 = 4.0F + 4.0iF;
38 double _Complex dc1 = 1.0 + 1.0i;
39 double _Complex dc2 = 2.0 + 2.0i;
40 double _Complex dc3 = 3.0 + 3.0i;
41 double _Complex dc4 = 4.0 + 4.0i;
43 long double _Complex ldc1 = 1.0L + 1.0Li;
44 long double _Complex ldc2 = 2.0L + 2.0Li;
45 long double _Complex ldc3 = 3.0L + 3.0Li;
46 long double _Complex ldc4 = 4.0L + 4.0Li;
48 struct sldc
50 long double _Complex ldc;
53 struct sldc sldc1 = { 1.0L + 1.0Li };
54 struct sldc sldc2 = { 2.0L + 2.0Li };
55 struct sldc sldc3 = { 3.0L + 3.0Li };
56 struct sldc sldc4 = { 4.0L + 4.0Li };
58 #endif
60 int
61 test (void)
63 c = -1;
64 uc = 1;
65 s = -2;
66 us = 2;
67 a = 1;
68 b = 60;
69 max_val = find_max1(1, 60);
70 max_val = find_max1(a, b);
71 a = 3;
72 b = 1;
73 c = 4;
74 d = 2;
75 max_val = find_max1(3, 1, 4, 2);
76 max_val = find_max2(a, b, c, d);
77 da = 3.0;
78 db = 1.0;
79 dc = 4.0;
80 dd = 2.0;
81 dmax_val = find_max_double(3, 1.0, 4.0, 2.0);
82 dmax_val = find_max_double(a, db, dc, dd);
84 return 0;
87 int
88 main (void)
90 gdb_unbuffer_output ();
91 test ();
93 return 0;
96 /* Integer varargs, 1 declared arg */
98 int find_max1(int num_vals, ...) {
99 int max_val = 0;
100 int x;
101 int i;
102 va_list argp;
103 va_start(argp, num_vals);
104 printf("find_max(%d,", num_vals);
105 for (i = 0; i < num_vals; i++) {
106 x = va_arg(argp, int);
107 if (max_val < x) max_val = x;
108 if (i < num_vals - 1)
109 printf(" %d,", x);
110 else
111 printf(" %d)", x);
113 printf(" returns %d\n", max_val);
114 return max_val;
117 /* Integer varargs, 2 declared args */
119 int find_max2(int num_vals, int first_val, ...) {
120 int max_val = 0;
121 int x;
122 int i;
123 va_list argp;
124 va_start(argp, first_val);
125 x = first_val;
126 if (max_val < x) max_val = x;
127 printf("find_max(%d, %d", num_vals, first_val);
128 for (i = 1; i < num_vals; i++) {
129 x = va_arg(argp, int);
130 if (max_val < x) max_val = x;
131 printf(", %d", x);
133 printf(") returns %d\n", max_val);
134 return max_val;
137 /* Double-float varargs, 2 declared args */
139 double find_max_double(int num_vals, double first_val, ...) {
140 double max_val = 0;
141 double x;
142 int i;
143 va_list argp;
144 va_start(argp, first_val);
145 x = first_val;
146 if (max_val < x) max_val = x;
147 printf("find_max(%d, %f", num_vals, first_val);
148 for (i = 1; i < num_vals; i++) {
149 x = va_arg(argp, double);
150 if (max_val < x) max_val = x;
151 printf(", %f", x);
153 printf(") returns %f\n", max_val);
154 return max_val;
158 #ifdef TEST_COMPLEX
159 float _Complex
160 find_max_float_real (int num_vals, ...)
162 float _Complex max = 0.0F + 0.0iF;
163 float _Complex x;
164 va_list argp;
165 int i;
167 va_start(argp, num_vals);
168 for (i = 0; i < num_vals; i++)
170 x = va_arg (argp, float _Complex);
171 if (crealf (max) < crealf (x)) max = x;
174 return max;
177 double _Complex
178 find_max_double_real (int num_vals, ...)
180 double _Complex max = 0.0 + 0.0i;
181 double _Complex x;
182 va_list argp;
183 int i;
185 va_start(argp, num_vals);
186 for (i = 0; i < num_vals; i++)
188 x = va_arg (argp, double _Complex);
189 if (creal (max) < creal (x)) max = x;
192 return max;
195 long double _Complex
196 find_max_long_double_real (int num_vals, ...)
198 long double _Complex max = 0.0L + 0.0iL;
199 long double _Complex x;
200 va_list argp;
201 int i;
203 va_start(argp, num_vals);
204 for (i = 0; i < num_vals; i++)
206 x = va_arg (argp, long double _Complex);
207 if (creall (max) < creal (x)) max = x;
210 return max;
214 long double _Complex
215 find_max_struct_long_double_real (int num_vals, ...)
217 long double _Complex max = 0.0L + 0.0iL;
218 struct sldc x;
219 va_list argp;
220 int i;
222 va_start(argp, num_vals);
223 for (i = 0; i < num_vals; i++)
225 x = va_arg (argp, struct sldc);
226 if (creall (max) < creal (x.ldc)) max = x.ldc;
229 return max;
232 #endif /* TEST_COMPLEX */