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, ...);
33 max_val
= find_max1(1, 60);
34 max_val
= find_max1(a
, b
);
39 max_val
= find_max1(3, 1, 4, 2);
40 max_val
= find_max2(a
, b
, c
, d
);
45 dmax_val
= find_max_double(3, 1.0, 4.0, 2.0);
46 dmax_val
= find_max_double(a
, db
, dc
, dd
);
51 /* Integer varargs, 1 declared arg */
53 int find_max1(int num_vals
, ...) {
58 va_start(argp
, num_vals
);
59 printf("find_max(%d,", num_vals
);
60 for (i
= 0; i
< num_vals
; i
++) {
61 x
= va_arg(argp
, int);
62 if (max_val
< x
) max_val
= x
;
68 printf(" returns %d\n", max_val
);
72 /* Integer varargs, 2 declared args */
74 int find_max2(int num_vals
, int first_val
, ...) {
79 va_start(argp
, first_val
);
81 if (max_val
< x
) max_val
= x
;
82 printf("find_max(%d, %d", num_vals
, first_val
);
83 for (i
= 1; i
< num_vals
; i
++) {
84 x
= va_arg(argp
, int);
85 if (max_val
< x
) max_val
= x
;
88 printf(") returns %d\n", max_val
);
92 /* Double-float varargs, 2 declared args */
94 double find_max_double(int num_vals
, double first_val
, ...) {
99 va_start(argp
, first_val
);
101 if (max_val
< x
) max_val
= x
;
102 printf("find_max(%d, %f", num_vals
, first_val
);
103 for (i
= 1; i
< num_vals
; i
++) {
104 x
= va_arg(argp
, double);
105 if (max_val
< x
) max_val
= x
;
108 printf(") returns %f\n", max_val
);