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.
11 #include "unbuffer_output.c"
13 int find_max1(int, ...);
14 int find_max2(int, int, ...);
15 double find_max_double(int, double, ...);
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
;
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
};
69 max_val
= find_max1(1, 60);
70 max_val
= find_max1(a
, b
);
75 max_val
= find_max1(3, 1, 4, 2);
76 max_val
= find_max2(a
, b
, c
, d
);
81 dmax_val
= find_max_double(3, 1.0, 4.0, 2.0);
82 dmax_val
= find_max_double(a
, db
, dc
, dd
);
90 gdb_unbuffer_output ();
96 /* Integer varargs, 1 declared arg */
98 int find_max1(int num_vals
, ...) {
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)
113 printf(" returns %d\n", max_val
);
117 /* Integer varargs, 2 declared args */
119 int find_max2(int num_vals
, int first_val
, ...) {
124 va_start(argp
, 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
;
133 printf(") returns %d\n", max_val
);
137 /* Double-float varargs, 2 declared args */
139 double find_max_double(int num_vals
, double first_val
, ...) {
144 va_start(argp
, 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
;
153 printf(") returns %f\n", max_val
);
160 find_max_float_real (int num_vals
, ...)
162 float _Complex max
= 0.0F
+ 0.0iF
;
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
;
178 find_max_double_real (int num_vals
, ...)
180 double _Complex max
= 0.0 + 0.0i
;
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
;
196 find_max_long_double_real (int num_vals
, ...)
198 long double _Complex max
= 0.0L + 0.0iL
;
199 long double _Complex x
;
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
;
215 find_max_struct_long_double_real (int num_vals
, ...)
217 long double _Complex max
= 0.0L + 0.0iL
;
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
;
232 #endif /* TEST_COMPLEX */