[gdb/testsuite] Reduce errors after gdb exit in default_gdb_start
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / varargs.c
CommitLineData
c906108c
SS
1/* varargs.c -
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.
5 * - RT 9/27/95
6 */
7
8#include <stdio.h>
9#include <stdarg.h>
10
dedad4e3
PA
11#include "../lib/unbuffer_output.c"
12
c906108c
SS
13int find_max1(int, ...);
14int find_max2(int, int, ...);
15double find_max_double(int, double, ...);
16
17char ch;
18unsigned char uc;
19short s;
20unsigned short us;
21int a,b,c,d;
22int max_val;
085dd6e6 23long long ll;
c906108c
SS
24float fa,fb,fc,fd;
25double da,db,dc,dd;
26double dmax_val;
27
6680506e
YQ
28#ifdef TEST_COMPLEX
29extern float crealf (float _Complex);
30extern double creal (double _Complex);
31extern long double creall (long double _Complex);
32
33float _Complex fc1 = 1.0F + 1.0iF;
34float _Complex fc2 = 2.0F + 2.0iF;
35float _Complex fc3 = 3.0F + 3.0iF;
36float _Complex fc4 = 4.0F + 4.0iF;
37
38double _Complex dc1 = 1.0 + 1.0i;
39double _Complex dc2 = 2.0 + 2.0i;
40double _Complex dc3 = 3.0 + 3.0i;
41double _Complex dc4 = 4.0 + 4.0i;
42
43long double _Complex ldc1 = 1.0L + 1.0Li;
44long double _Complex ldc2 = 2.0L + 2.0Li;
45long double _Complex ldc3 = 3.0L + 3.0Li;
46long double _Complex ldc4 = 4.0L + 4.0Li;
47
48#endif
49
dedad4e3
PA
50int
51test (void)
52{
c906108c
SS
53 c = -1;
54 uc = 1;
55 s = -2;
56 us = 2;
57 a = 1;
58 b = 60;
59 max_val = find_max1(1, 60);
60 max_val = find_max1(a, b);
61 a = 3;
62 b = 1;
63 c = 4;
64 d = 2;
65 max_val = find_max1(3, 1, 4, 2);
66 max_val = find_max2(a, b, c, d);
67 da = 3.0;
68 db = 1.0;
69 dc = 4.0;
70 dd = 2.0;
71 dmax_val = find_max_double(3, 1.0, 4.0, 2.0);
72 dmax_val = find_max_double(a, db, dc, dd);
085dd6e6
JM
73
74 return 0;
c906108c
SS
75}
76
dedad4e3
PA
77int
78main (void)
79{
80 gdb_unbuffer_output ();
81 test ();
82}
83
c906108c
SS
84/* Integer varargs, 1 declared arg */
85
86int find_max1(int num_vals, ...) {
87 int max_val = 0;
88 int x;
89 int i;
90 va_list argp;
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;
96 if (i < num_vals - 1)
97 printf(" %d,", x);
98 else
99 printf(" %d)", x);
100 }
101 printf(" returns %d\n", max_val);
102 return max_val;
103}
104
105/* Integer varargs, 2 declared args */
106
107int find_max2(int num_vals, int first_val, ...) {
108 int max_val = 0;
109 int x;
110 int i;
111 va_list argp;
112 va_start(argp, first_val);
113 x = 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;
119 printf(", %d", x);
120 }
121 printf(") returns %d\n", max_val);
122 return max_val;
123}
124
125/* Double-float varargs, 2 declared args */
126
127double find_max_double(int num_vals, double first_val, ...) {
128 double max_val = 0;
129 double x;
130 int i;
131 va_list argp;
132 va_start(argp, first_val);
133 x = first_val;
134 if (max_val < x) max_val = x;
d8f92b1f 135 printf("find_max(%d, %f", num_vals, first_val);
c906108c
SS
136 for (i = 1; i < num_vals; i++) {
137 x = va_arg(argp, double);
138 if (max_val < x) max_val = x;
139 printf(", %f", x);
140 }
141 printf(") returns %f\n", max_val);
142 return max_val;
143}
144
6680506e
YQ
145
146#ifdef TEST_COMPLEX
147float _Complex
148find_max_float_real (int num_vals, ...)
149{
150 float _Complex max = 0.0F + 0.0iF;
151 float _Complex x;
152 va_list argp;
153 int i;
154
155 va_start(argp, num_vals);
156 for (i = 0; i < num_vals; i++)
157 {
158 x = va_arg (argp, float _Complex);
159 if (crealf (max) < crealf (x)) max = x;
160 }
161
162 return max;
163}
164
165double _Complex
166find_max_double_real (int num_vals, ...)
167{
168 double _Complex max = 0.0 + 0.0i;
169 double _Complex x;
170 va_list argp;
171 int i;
172
173 va_start(argp, num_vals);
174 for (i = 0; i < num_vals; i++)
175 {
176 x = va_arg (argp, double _Complex);
177 if (creal (max) < creal (x)) max = x;
178 }
179
180 return max;
181}
182
183long double _Complex
184find_max_long_double_real (int num_vals, ...)
185{
186 long double _Complex max = 0.0L + 0.0iL;
187 long double _Complex x;
188 va_list argp;
189 int i;
190
191 va_start(argp, num_vals);
192 for (i = 0; i < num_vals; i++)
193 {
194 x = va_arg (argp, long double _Complex);
195 if (creall (max) < creal (x)) max = x;
196 }
197
198 return max;
199}
200
201
202#endif /* TEST_COMPLEX */
This page took 2.29016 seconds and 4 git commands to generate.