gdb/python: don't allow the user to delete window title attributes
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / varargs.c
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
11 #include "../lib/unbuffer_output.c"
12
13 int find_max1(int, ...);
14 int find_max2(int, int, ...);
15 double find_max_double(int, double, ...);
16
17 char ch;
18 unsigned char uc;
19 short s;
20 unsigned short us;
21 int a,b,c,d;
22 int max_val;
23 long long ll;
24 float fa,fb,fc,fd;
25 double da,db,dc,dd;
26 double dmax_val;
27
28 #ifdef TEST_COMPLEX
29 extern float crealf (float _Complex);
30 extern double creal (double _Complex);
31 extern long double creall (long double _Complex);
32
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;
37
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;
42
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;
47
48 #endif
49
50 int
51 test (void)
52 {
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);
73
74 return 0;
75 }
76
77 int
78 main (void)
79 {
80 gdb_unbuffer_output ();
81 test ();
82
83 return 0;
84 }
85
86 /* Integer varargs, 1 declared arg */
87
88 int find_max1(int num_vals, ...) {
89 int max_val = 0;
90 int x;
91 int i;
92 va_list argp;
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;
98 if (i < num_vals - 1)
99 printf(" %d,", x);
100 else
101 printf(" %d)", x);
102 }
103 printf(" returns %d\n", max_val);
104 return max_val;
105 }
106
107 /* Integer varargs, 2 declared args */
108
109 int find_max2(int num_vals, int first_val, ...) {
110 int max_val = 0;
111 int x;
112 int i;
113 va_list argp;
114 va_start(argp, first_val);
115 x = 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;
121 printf(", %d", x);
122 }
123 printf(") returns %d\n", max_val);
124 return max_val;
125 }
126
127 /* Double-float varargs, 2 declared args */
128
129 double find_max_double(int num_vals, double first_val, ...) {
130 double max_val = 0;
131 double x;
132 int i;
133 va_list argp;
134 va_start(argp, first_val);
135 x = 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;
141 printf(", %f", x);
142 }
143 printf(") returns %f\n", max_val);
144 return max_val;
145 }
146
147
148 #ifdef TEST_COMPLEX
149 float _Complex
150 find_max_float_real (int num_vals, ...)
151 {
152 float _Complex max = 0.0F + 0.0iF;
153 float _Complex x;
154 va_list argp;
155 int i;
156
157 va_start(argp, num_vals);
158 for (i = 0; i < num_vals; i++)
159 {
160 x = va_arg (argp, float _Complex);
161 if (crealf (max) < crealf (x)) max = x;
162 }
163
164 return max;
165 }
166
167 double _Complex
168 find_max_double_real (int num_vals, ...)
169 {
170 double _Complex max = 0.0 + 0.0i;
171 double _Complex x;
172 va_list argp;
173 int i;
174
175 va_start(argp, num_vals);
176 for (i = 0; i < num_vals; i++)
177 {
178 x = va_arg (argp, double _Complex);
179 if (creal (max) < creal (x)) max = x;
180 }
181
182 return max;
183 }
184
185 long double _Complex
186 find_max_long_double_real (int num_vals, ...)
187 {
188 long double _Complex max = 0.0L + 0.0iL;
189 long double _Complex x;
190 va_list argp;
191 int i;
192
193 va_start(argp, num_vals);
194 for (i = 0; i < num_vals; i++)
195 {
196 x = va_arg (argp, long double _Complex);
197 if (creall (max) < creal (x)) max = x;
198 }
199
200 return max;
201 }
202
203
204 #endif /* TEST_COMPLEX */
This page took 0.042557 seconds and 4 git commands to generate.