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 int find_max1(int, ...);
12 int find_max2(int, int, ...);
13 double find_max_double(int, double, ...);
27 extern float crealf (float _Complex
);
28 extern double creal (double _Complex
);
29 extern long double creall (long double _Complex
);
31 float _Complex fc1
= 1.0F
+ 1.0iF
;
32 float _Complex fc2
= 2.0F
+ 2.0iF
;
33 float _Complex fc3
= 3.0F
+ 3.0iF
;
34 float _Complex fc4
= 4.0F
+ 4.0iF
;
36 double _Complex dc1
= 1.0 + 1.0i
;
37 double _Complex dc2
= 2.0 + 2.0i
;
38 double _Complex dc3
= 3.0 + 3.0i
;
39 double _Complex dc4
= 4.0 + 4.0i
;
41 long double _Complex ldc1
= 1.0L + 1.0Li
;
42 long double _Complex ldc2
= 2.0L + 2.0Li
;
43 long double _Complex ldc3
= 3.0L + 3.0Li
;
44 long double _Complex ldc4
= 4.0L + 4.0Li
;
55 max_val
= find_max1(1, 60);
56 max_val
= find_max1(a
, b
);
61 max_val
= find_max1(3, 1, 4, 2);
62 max_val
= find_max2(a
, b
, c
, d
);
67 dmax_val
= find_max_double(3, 1.0, 4.0, 2.0);
68 dmax_val
= find_max_double(a
, db
, dc
, dd
);
73 /* Integer varargs, 1 declared arg */
75 int find_max1(int num_vals
, ...) {
80 va_start(argp
, num_vals
);
81 printf("find_max(%d,", num_vals
);
82 for (i
= 0; i
< num_vals
; i
++) {
83 x
= va_arg(argp
, int);
84 if (max_val
< x
) max_val
= x
;
90 printf(" returns %d\n", max_val
);
94 /* Integer varargs, 2 declared args */
96 int find_max2(int num_vals
, int first_val
, ...) {
101 va_start(argp
, first_val
);
103 if (max_val
< x
) max_val
= x
;
104 printf("find_max(%d, %d", num_vals
, first_val
);
105 for (i
= 1; i
< num_vals
; i
++) {
106 x
= va_arg(argp
, int);
107 if (max_val
< x
) max_val
= x
;
110 printf(") returns %d\n", max_val
);
114 /* Double-float varargs, 2 declared args */
116 double find_max_double(int num_vals
, double first_val
, ...) {
121 va_start(argp
, first_val
);
123 if (max_val
< x
) max_val
= x
;
124 printf("find_max(%d, %f", num_vals
, first_val
);
125 for (i
= 1; i
< num_vals
; i
++) {
126 x
= va_arg(argp
, double);
127 if (max_val
< x
) max_val
= x
;
130 printf(") returns %f\n", max_val
);
137 find_max_float_real (int num_vals
, ...)
139 float _Complex max
= 0.0F
+ 0.0iF
;
144 va_start(argp
, num_vals
);
145 for (i
= 0; i
< num_vals
; i
++)
147 x
= va_arg (argp
, float _Complex
);
148 if (crealf (max
) < crealf (x
)) max
= x
;
155 find_max_double_real (int num_vals
, ...)
157 double _Complex max
= 0.0 + 0.0i
;
162 va_start(argp
, num_vals
);
163 for (i
= 0; i
< num_vals
; i
++)
165 x
= va_arg (argp
, double _Complex
);
166 if (creal (max
) < creal (x
)) max
= x
;
173 find_max_long_double_real (int num_vals
, ...)
175 long double _Complex max
= 0.0L + 0.0iL
;
176 long double _Complex x
;
180 va_start(argp
, num_vals
);
181 for (i
= 0; i
< num_vals
; i
++)
183 x
= va_arg (argp
, long double _Complex
);
184 if (creall (max
) < creal (x
)) max
= x
;
191 #endif /* TEST_COMPLEX */
This page took 0.03323 seconds and 4 git commands to generate.