1/* 2 * Test file with lots of different types, for testing the 3 * "ptype" command. 4 */ 5 6/* 7 * First the basic C types. 8 */ 9#include <stdlib.h> 10 11#if !defined (__STDC__) && !defined (_AIX) 12#define signed /**/ 13#endif 14 15char v_char; 16signed char v_signed_char; 17unsigned char v_unsigned_char; 18 19short v_short; 20signed short v_signed_short; 21unsigned short v_unsigned_short; 22 23int v_int; 24signed int v_signed_int; 25unsigned int v_unsigned_int; 26 27long v_long; 28signed long v_signed_long; 29unsigned long v_unsigned_long; 30 31float v_float; 32double v_double; 33 34/* 35 * Now some derived types, which are arrays, functions-returning, 36 * pointers, structures, unions, and enumerations. 37 */ 38 39/**** arrays *******/ 40 41char v_char_array[2]; 42signed char v_signed_char_array[2]; 43unsigned char v_unsigned_char_array[2]; 44 45short v_short_array[2]; 46signed short v_signed_short_array[2]; 47unsigned short v_unsigned_short_array[2]; 48 49int v_int_array[2]; 50signed int v_signed_int_array[2]; 51unsigned int v_unsigned_int_array[2]; 52 53long v_long_array[2]; 54signed long v_signed_long_array[2]; 55unsigned long v_unsigned_long_array[2]; 56 57float v_float_array[2]; 58double v_double_array[2]; 59 60/* PR 3742 */ 61typedef char t_char_array[]; 62t_char_array *pv_char_array; 63 64/**** pointers *******/ 65 66char *v_char_pointer; 67signed char *v_signed_char_pointer; 68unsigned char *v_unsigned_char_pointer; 69 70short *v_short_pointer; 71signed short *v_signed_short_pointer; 72unsigned short *v_unsigned_short_pointer; 73 74int *v_int_pointer; 75signed int *v_signed_int_pointer; 76unsigned int *v_unsigned_int_pointer; 77 78long *v_long_pointer; 79signed long *v_signed_long_pointer; 80unsigned long *v_unsigned_long_pointer; 81 82float *v_float_pointer; 83double *v_double_pointer; 84 85/**** structs *******/ 86 87struct t_struct { 88 char v_char_member; 89 short v_short_member; 90 int v_int_member; 91 long v_long_member; 92 float v_float_member; 93 double v_double_member; 94} v_struct1; 95 96struct t_struct *v_t_struct_p; 97 98struct { 99 char v_char_member; 100 short v_short_member; 101 int v_int_member; 102 long v_long_member; 103 float v_float_member; 104 double v_double_member; 105} v_struct2; 106 107/* typedef'd struct without a tag. */ 108typedef struct { 109 double v_double_member; 110 int v_int_member; 111} t_struct3; 112/* GCC seems to want a variable of this type, or else it won't put out 113 a symbol. */ 114t_struct3 v_struct3; 115 116/**** unions *******/ 117 118union t_union { 119 char v_char_member; 120 short v_short_member; 121 int v_int_member; 122 long v_long_member; 123 float v_float_member; 124 double v_double_member; 125} v_union; 126 127union { 128 char v_char_member; 129 short v_short_member; 130 int v_int_member; 131 long v_long_member; 132 float v_float_member; 133 double v_double_member; 134} v_union2; 135 136/* typedef'd union without a tag. */ 137typedef union { 138 double v_double_member; 139 int v_int_member; 140} t_union3; 141/* GCC seems to want a variable of this type, or else it won't put out 142 a symbol. */ 143t_union3 v_union3; 144 145/*** Functions returning type ********/ 146 147char v_char_func () { return(0); } 148signed char v_signed_char_func () { return (0); } 149unsigned char v_unsigned_char_func () { return (0); } 150 151short v_short_func () { return (0); } 152signed short v_signed_short_func () { return (0); } 153unsigned short v_unsigned_short_func () { return (0); } 154 155int v_int_func () { return (0); } 156signed int v_signed_int_func () { return (0); } 157unsigned int v_unsigned_int_func () { return (0); } 158 159long v_long_func () { return (0); } 160signed long v_signed_long_func () { return (0); } 161unsigned long v_unsigned_long_func () { return (0); } 162 163float v_float_func () { return (0.0); } 164double v_double_func () { return (0.0); } 165 166/**** Some misc more complicated things *******/ 167 168struct link { 169 struct link *next; 170#ifdef __STDC__ 171 struct link *(*linkfunc) (struct link *this, int flags); 172#else 173 struct link *(*linkfunc) (); 174#endif 175 struct t_struct stuff[1][2][3]; 176} *s_link; 177 178union tu_link { 179 struct link *next; 180#ifdef __STDC__ 181 struct link *(*linkfunc) (struct link *this, int flags); 182#else 183 struct link *(*linkfunc) (); 184#endif 185 struct t_struct stuff[1][2][3]; 186} u_link; 187 188struct outer_struct { 189 int outer_int; 190 struct inner_struct { 191 int inner_int; 192 long inner_long; 193 }inner_struct_instance; 194 union inner_union { 195 int inner_union_int; 196 long inner_union_long; 197 }inner_union_instance; 198 long outer_long; 199} nested_su; 200 201/**** Enumerations *******/ 202 203enum 204/* Work around the bug for compilers which don't put out the right stabs. */ 205#if __GNUC__ < 2 && !defined (_AIX) 206primary1_tag 207#endif 208{red1, green1, blue1} primary1; 209 210enum {red, green, blue} primary; 211enum colors {yellow, purple, pink} nonprimary; 212 213enum {chevy, ford} clunker; 214enum cars {bmw, porsche} sportscar; 215 216#undef FALSE 217#undef TRUE 218typedef enum {FALSE, TRUE} boolean; 219boolean v_boolean; 220/*note: aCC has bool type predefined with 'false' and 'true'*/ 221typedef enum bvals {my_false, my_true} boolean2; 222boolean2 v_boolean2; 223 224enum misordered {two = 2, one = 1, zero = 0, three = 3}; 225 226/* Seems like we need a variable of this type to get the type to be put 227 in the executable, at least for AIX xlc. */ 228enum misordered v_misordered = three; 229 230/**** Pointers to functions *******/ 231 232typedef int (*func_type) (int (*) (int, float), float); 233double (*old_fptr) (); 234double (*new_fptr) (void); 235int (*fptr) (int, float); 236int *(*fptr2) (int (*) (int, float), float); 237int (*xptr) (int (*) (), int (*) (void), int); 238int (*(*ffptr) (char)) (short); 239int (*(*(*fffptr) (char)) (short)) (long); 240 241func_type v_func_type; 242 243/* Here are the sort of stabs we expect to see for the above: 244 245 .stabs "func_type:t(0,100)=*(0,101)=g(0,1)(0,102)=*(0,103)=g(0,1)(0,1)(0,14)#(0,14)#",128,0,234,0 246 .stabs "old_fptr:G(0,110)=*(0,111)=f(0,15)",32,0,231,0 247 .stabs "new_fptr:G(0,120)=*(0,121)=g(0,15)(0,122)=(0,122)#",32,0,232,0 248 .stabs "fptr:G(0,130)=*(0,103)#",32,0,233,0 249 .stabs "fptr2:G(0,140)=*(0,141)=g(0,142)=*(0,1)(0,102)(0,14)#",32,0,235,0 250 .stabs "xptr:G(0,150)=*(0,151)=g(0,1)(0,152)=*(0,153)=f(0,1)(0,154)=*(0,155)=g(0,1)(0,122)#(0,1)#",32,0,236,0 251 .stabs "ffptr:G(0,160)=*(0,161)=g(0,162)=*(0,163)=g(0,1)(0,8)#(0,2)#",32,0,237,0\ 252 .stabs "fffptr:G(0,170)=*(0,171)=g(0,172)=*(0,173)=g(0,174)=*(0,175)=g(0,1)(0,3)#(0,8)#(0,2)#",32,0,237,0 253 254 Most of these use Sun's extension for prototyped function types --- 255 the 'g' type descriptor. As of around 9 Feb 2002, GCC didn't emit 256 those, but GDB can read them, so the related tests in ptype.exp 257 will all xfail. */ 258 259 260/***********/ 261 262typedef int foo; 263 264foo intfoo (afoo) 265{ 266 return (afoo * 2); 267} 268 269/***********/ 270 271int main () 272{ 273 /* Ensure that malloc is a pointer type; avoid use of "void" and any include files. */ 274/* extern char *malloc();*/ 275 276 /* Some of the tests in ptype.exp require invoking malloc, so make 277 sure it is linked in to this program. */ 278 v_char_pointer = (char *) malloc (1); 279 280#ifdef usestubs 281 set_debug_traps(); 282 breakpoint(); 283#endif 284 /* Some linkers (e.g. on AIX) remove unreferenced variables, 285 so make sure to reference them. */ 286 primary = blue; 287 primary1 = blue1; 288 nonprimary = pink; 289 sportscar = porsche; 290 clunker = ford; 291 v_struct1.v_int_member = 5; 292 v_struct2.v_int_member = 6; 293 v_struct3.v_int_member = 7; 294 295 v_char = 0; 296 v_signed_char = 0; 297 v_unsigned_char = 0; 298 299 v_short = 0; 300 v_signed_short = 0; 301 v_unsigned_short = 0; 302 303 v_int = 0; 304 v_signed_int = 0; 305 v_unsigned_int = 0; 306 307 v_long = 0; 308 v_signed_long = 0; 309 v_unsigned_long = 0; 310 311 v_float = 0; 312 v_double = 0; 313 314 v_char_array[0] = 0; 315 v_signed_char_array[0] = 0; 316 v_unsigned_char_array[0] = 0; 317 318 v_short_array[0] = 0; 319 v_signed_short_array[0] = 0; 320 v_unsigned_short_array[0] = 0; 321 322 v_int_array[0] = 0; 323 v_signed_int_array[0] = 0; 324 v_unsigned_int_array[0] = 0; 325 326 v_long_array[0] = 0; 327 v_signed_long_array[0] = 0; 328 v_unsigned_long_array[0] = 0; 329 330 v_float_array[0] = 0; 331 v_double_array[0] = 0; 332 333 v_char_pointer = 0; 334 v_signed_char_pointer = 0; 335 v_unsigned_char_pointer = 0; 336 337 v_short_pointer = 0; 338 v_signed_short_pointer = 0; 339 v_unsigned_short_pointer = 0; 340 341 v_int_pointer = 0; 342 v_signed_int_pointer = 0; 343 v_unsigned_int_pointer = 0; 344 345 v_long_pointer = 0; 346 v_signed_long_pointer = 0; 347 v_unsigned_long_pointer = 0; 348 349 v_float_pointer = 0; 350 v_double_pointer = 0; 351 352 nested_su.outer_int = 0; 353 v_t_struct_p = 0; 354 355 v_boolean = FALSE; 356 v_boolean2 = my_false; 357 return 0; 358} 359