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 "../lib/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
;
59 max_val
= find_max1(1, 60);
60 max_val
= find_max1(a
, b
);
65 max_val
= find_max1(3, 1, 4, 2);
66 max_val
= find_max2(a
, b
, c
, d
);
71 dmax_val
= find_max_double(3, 1.0, 4.0, 2.0);
72 dmax_val
= find_max_double(a
, db
, dc
, dd
);
80 gdb_unbuffer_output ();
84 /* Integer varargs, 1 declared arg */
86 int find_max1(int num_vals
, ...) {
91 va_start(argp
, num_vals
);
92 printf("find_max(%d,", num_vals
);
93 for (i
= 0; i
< num_vals
; i
++) {
94 x
= va_arg(argp
, int);
95 if (max_val
< x
) max_val
= x
;
101 printf(" returns %d\n", max_val
);
105 /* Integer varargs, 2 declared args */
107 int find_max2(int num_vals
, int first_val
, ...) {
112 va_start(argp
, first_val
);
114 if (max_val
< x
) max_val
= x
;
115 printf("find_max(%d, %d", num_vals
, first_val
);
116 for (i
= 1; i
< num_vals
; i
++) {
117 x
= va_arg(argp
, int);
118 if (max_val
< x
) max_val
= x
;
121 printf(") returns %d\n", max_val
);
125 /* Double-float varargs, 2 declared args */
127 double find_max_double(int num_vals
, double first_val
, ...) {
132 va_start(argp
, first_val
);
134 if (max_val
< x
) max_val
= x
;
135 printf("find_max(%d, %f", num_vals
, first_val
);
136 for (i
= 1; i
< num_vals
; i
++) {
137 x
= va_arg(argp
, double);
138 if (max_val
< x
) max_val
= x
;
141 printf(") returns %f\n", max_val
);
148 find_max_float_real (int num_vals
, ...)
150 float _Complex max
= 0.0F
+ 0.0iF
;
155 va_start(argp
, num_vals
);
156 for (i
= 0; i
< num_vals
; i
++)
158 x
= va_arg (argp
, float _Complex
);
159 if (crealf (max
) < crealf (x
)) max
= x
;
166 find_max_double_real (int num_vals
, ...)
168 double _Complex max
= 0.0 + 0.0i
;
173 va_start(argp
, num_vals
);
174 for (i
= 0; i
< num_vals
; i
++)
176 x
= va_arg (argp
, double _Complex
);
177 if (creal (max
) < creal (x
)) max
= x
;
184 find_max_long_double_real (int num_vals
, ...)
186 long double _Complex max
= 0.0L + 0.0iL
;
187 long double _Complex x
;
191 va_start(argp
, num_vals
);
192 for (i
= 0; i
< num_vals
; i
++)
194 x
= va_arg (argp
, long double _Complex
);
195 if (creall (max
) < creal (x
)) max
= x
;
202 #endif /* TEST_COMPLEX */