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