Switch the license of all .c files to GPLv3.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / whatis.c
1 /* This test program is part of GDB, the GNU debugger.
2
3 Copyright 1992, 1993, 1994, 1997, 1999, 2004, 2007
4 Free Software Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /*
21 * Test file with lots of different types, for testing the
22 * "whatis" command.
23 */
24
25 /*
26 * First the basic C types.
27 */
28
29 char v_char;
30 signed char v_signed_char;
31 unsigned char v_unsigned_char;
32
33 short v_short;
34 signed short v_signed_short;
35 unsigned short v_unsigned_short;
36
37 int v_int;
38 signed int v_signed_int;
39 unsigned int v_unsigned_int;
40
41 long v_long;
42 signed long v_signed_long;
43 unsigned long v_unsigned_long;
44
45 float v_float;
46 double v_double;
47
48 /*
49 * Now some derived types, which are arrays, functions-returning,
50 * pointers, structures, unions, and enumerations.
51 */
52
53 /**** arrays *******/
54
55 char v_char_array[2];
56 signed char v_signed_char_array[2];
57 unsigned char v_unsigned_char_array[2];
58
59 short v_short_array[2];
60 signed short v_signed_short_array[2];
61 unsigned short v_unsigned_short_array[2];
62
63 int v_int_array[2];
64 signed int v_signed_int_array[2];
65 unsigned int v_unsigned_int_array[2];
66
67 long v_long_array[2];
68 signed long v_signed_long_array[2];
69 unsigned long v_unsigned_long_array[2];
70
71 float v_float_array[2];
72 double v_double_array[2];
73
74 /**** pointers *******/
75
76 /* Make sure they still print as pointer to foo even there is a typedef
77 for that type. Test this not just for char *, which might be
78 a special case kludge in GDB (Unix system include files like to define
79 caddr_t), but for a variety of types. */
80 typedef char *char_addr;
81 static char_addr a_char_addr;
82 typedef unsigned short *ushort_addr;
83 static ushort_addr a_ushort_addr;
84 typedef signed long *slong_addr;
85 static slong_addr a_slong_addr;
86
87 char *v_char_pointer;
88 signed char *v_signed_char_pointer;
89 unsigned char *v_unsigned_char_pointer;
90
91 short *v_short_pointer;
92 signed short *v_signed_short_pointer;
93 unsigned short *v_unsigned_short_pointer;
94
95 int *v_int_pointer;
96 signed int *v_signed_int_pointer;
97 unsigned int *v_unsigned_int_pointer;
98
99 long *v_long_pointer;
100 signed long *v_signed_long_pointer;
101 unsigned long *v_unsigned_long_pointer;
102
103 float *v_float_pointer;
104 double *v_double_pointer;
105
106 /**** structs *******/
107
108 struct t_struct {
109 char v_char_member;
110 short v_short_member;
111 int v_int_member;
112 long v_long_member;
113 float v_float_member;
114 double v_double_member;
115 } v_struct1;
116
117 struct {
118 char v_char_member;
119 short v_short_member;
120 int v_int_member;
121 long v_long_member;
122 float v_float_member;
123 double v_double_member;
124 } v_struct2;
125
126 /**** unions *******/
127
128 union t_union {
129 char v_char_member;
130 short v_short_member;
131 int v_int_member;
132 long v_long_member;
133 float v_float_member;
134 double v_double_member;
135 } v_union;
136
137 union {
138 char v_char_member;
139 short v_short_member;
140 int v_int_member;
141 long v_long_member;
142 float v_float_member;
143 double v_double_member;
144 } v_union2;
145
146 /*** Functions returning type ********/
147
148 char v_char_func () { return(0); }
149 signed char v_signed_char_func () { return (0); }
150 unsigned char v_unsigned_char_func () { return (0); }
151
152 short v_short_func () { return (0); }
153 signed short v_signed_short_func () { return (0); }
154 unsigned short v_unsigned_short_func () { return (0); }
155
156 int v_int_func () { return (0); }
157 signed int v_signed_int_func () { return (0); }
158 unsigned int v_unsigned_int_func () { return (0); }
159
160 long v_long_func () { return (0); }
161 signed long v_signed_long_func () { return (0); }
162 unsigned long v_unsigned_long_func () { return (0); }
163
164 float v_float_func () { return (0.0); }
165 double v_double_func () { return (0.0); }
166
167 /**** Some misc more complicated things *******/
168
169 struct link {
170 struct link *next;
171 #ifdef __STDC__
172 struct link *(*linkfunc) (struct link *this, int flags);
173 #else
174 struct link *(*linkfunc) ();
175 #endif
176 struct t_struct stuff[1][2][3];
177 } *s_link;
178
179 union tu_link {
180 struct link *next;
181 #ifdef __STDC__
182 struct link *(*linkfunc) (struct link *this, int flags);
183 #else
184 struct link *(*linkfunc) ();
185 #endif
186 struct t_struct stuff[1][2][3];
187 } u_link;
188
189 struct outer_struct {
190 int outer_int;
191 struct inner_struct {
192 int inner_int;
193 long inner_long;
194 }inner_struct_instance;
195 union inner_union {
196 int inner_union_int;
197 long inner_union_long;
198 }inner_union_instance;
199 long outer_long;
200 } nested_su;
201
202 /**** Enumerations *******/
203
204 enum colors {red, green, blue} color;
205 enum cars {chevy, ford, porsche} clunker;
206
207 /***********/
208
209 int main ()
210 {
211 #ifdef usestubs
212 set_debug_traps();
213 breakpoint();
214 #endif
215 /* Some linkers (e.g. on AIX) remove unreferenced variables,
216 so make sure to reference them. */
217 v_char = 0;
218 v_signed_char = 1;
219 v_unsigned_char = 2;
220
221 v_short = 3;
222 v_signed_short = 4;
223 v_unsigned_short = 5;
224
225 v_int = 6;
226 v_signed_int = 7;
227 v_unsigned_int = 8;
228
229 v_long = 9;
230 v_signed_long = 10;
231 v_unsigned_long = 11;
232
233 v_float = 100.0;
234 v_double = 200.0;
235
236
237 v_char_array[0] = v_char;
238 v_signed_char_array[0] = v_signed_char;
239 v_unsigned_char_array[0] = v_unsigned_char;
240
241 v_short_array[0] = v_short;
242 v_signed_short_array[0] = v_signed_short;
243 v_unsigned_short_array[0] = v_unsigned_short;
244
245 v_int_array[0] = v_int;
246 v_signed_int_array[0] = v_signed_int;
247 v_unsigned_int_array[0] = v_unsigned_int;
248
249 v_long_array[0] = v_long;
250 v_signed_long_array[0] = v_signed_long;
251 v_unsigned_long_array[0] = v_unsigned_long;
252
253 v_float_array[0] = v_float;
254 v_double_array[0] = v_double;
255
256 v_char_pointer = &v_char;
257 v_signed_char_pointer = &v_signed_char;
258 v_unsigned_char_pointer = &v_unsigned_char;
259
260 v_short_pointer = &v_short;
261 v_signed_short_pointer = &v_signed_short;
262 v_unsigned_short_pointer = &v_unsigned_short;
263
264 v_int_pointer = &v_int;
265 v_signed_int_pointer = &v_signed_int;
266 v_unsigned_int_pointer = &v_unsigned_int;
267
268 v_long_pointer = &v_long;
269 v_signed_long_pointer = &v_signed_long;
270 v_unsigned_long_pointer = &v_unsigned_long;
271
272 v_float_pointer = &v_float;
273 v_double_pointer = &v_double;
274
275 color = red;
276 clunker = porsche;
277
278 u_link.next = s_link;
279
280 v_union2.v_short_member = v_union.v_short_member;
281
282 v_struct1.v_char_member = 0;
283 v_struct2.v_char_member = 0;
284
285 nested_su.outer_int = 0;
286 return 0;
287 }
This page took 0.039618 seconds and 4 git commands to generate.