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 ();
86 /* Integer varargs, 1 declared arg */
88 int find_max1(int num_vals
, ...) {
93 va_start(argp
, num_vals
);
94 printf("find_max(%d,", num_vals
);
95 for (i
= 0; i
< num_vals
; i
++) {
96 x
= va_arg(argp
, int);
97 if (max_val
< x
) max_val
= x
;
103 printf(" returns %d\n", max_val
);
107 /* Integer varargs, 2 declared args */
109 int find_max2(int num_vals
, int first_val
, ...) {
114 va_start(argp
, first_val
);
116 if (max_val
< x
) max_val
= x
;
117 printf("find_max(%d, %d", num_vals
, first_val
);
118 for (i
= 1; i
< num_vals
; i
++) {
119 x
= va_arg(argp
, int);
120 if (max_val
< x
) max_val
= x
;
123 printf(") returns %d\n", max_val
);
127 /* Double-float varargs, 2 declared args */
129 double find_max_double(int num_vals
, double first_val
, ...) {
134 va_start(argp
, first_val
);
136 if (max_val
< x
) max_val
= x
;
137 printf("find_max(%d, %f", num_vals
, first_val
);
138 for (i
= 1; i
< num_vals
; i
++) {
139 x
= va_arg(argp
, double);
140 if (max_val
< x
) max_val
= x
;
143 printf(") returns %f\n", max_val
);
150 find_max_float_real (int num_vals
, ...)
152 float _Complex max
= 0.0F
+ 0.0iF
;
157 va_start(argp
, num_vals
);
158 for (i
= 0; i
< num_vals
; i
++)
160 x
= va_arg (argp
, float _Complex
);
161 if (crealf (max
) < crealf (x
)) max
= x
;
168 find_max_double_real (int num_vals
, ...)
170 double _Complex max
= 0.0 + 0.0i
;
175 va_start(argp
, num_vals
);
176 for (i
= 0; i
< num_vals
; i
++)
178 x
= va_arg (argp
, double _Complex
);
179 if (creal (max
) < creal (x
)) max
= x
;
186 find_max_long_double_real (int num_vals
, ...)
188 long double _Complex max
= 0.0L + 0.0iL
;
189 long double _Complex x
;
193 va_start(argp
, num_vals
);
194 for (i
= 0; i
< num_vals
; i
++)
196 x
= va_arg (argp
, long double _Complex
);
197 if (creall (max
) < creal (x
)) max
= x
;
204 #endif /* TEST_COMPLEX */
This page took 0.042557 seconds and 4 git commands to generate.