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, ...);
32 max_val
= find_max1(1, 60);
33 max_val
= find_max1(a
, b
);
38 max_val
= find_max1(3, 1, 4, 2);
39 max_val
= find_max2(a
, b
, c
, d
);
44 dmax_val
= find_max_double(3, 1.0, 4.0, 2.0);
45 dmax_val
= find_max_double(a
, db
, dc
, dd
);
48 /* Integer varargs, 1 declared arg */
50 int find_max1(int num_vals
, ...) {
55 va_start(argp
, num_vals
);
56 printf("find_max(%d,", num_vals
);
57 for (i
= 0; i
< num_vals
; i
++) {
58 x
= va_arg(argp
, int);
59 if (max_val
< x
) max_val
= x
;
65 printf(" returns %d\n", max_val
);
69 /* Integer varargs, 2 declared args */
71 int find_max2(int num_vals
, int first_val
, ...) {
76 va_start(argp
, first_val
);
78 if (max_val
< x
) max_val
= x
;
79 printf("find_max(%d, %d", num_vals
, first_val
);
80 for (i
= 1; i
< num_vals
; i
++) {
81 x
= va_arg(argp
, int);
82 if (max_val
< x
) max_val
= x
;
85 printf(") returns %d\n", max_val
);
89 /* Double-float varargs, 2 declared args */
91 double find_max_double(int num_vals
, double first_val
, ...) {
96 va_start(argp
, first_val
);
98 if (max_val
< x
) max_val
= x
;
99 printf("find_max(%f, %f", num_vals
, first_val
);
100 for (i
= 1; i
< num_vals
; i
++) {
101 x
= va_arg(argp
, double);
102 if (max_val
< x
) max_val
= x
;
105 printf(") returns %f\n", max_val
);
This page took 0.032313 seconds and 5 git commands to generate.