1 1.1 christos /* This testcase is part of GDB, the GNU debugger. 2 1.1 christos 3 1.1.1.3 christos Copyright 2019-2024 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos This program is free software; you can redistribute it and/or modify 6 1.1 christos it under the terms of the GNU General Public License as published by 7 1.1 christos the Free Software Foundation; either version 3 of the License, or 8 1.1 christos (at your option) any later version. 9 1.1 christos 10 1.1 christos This program is distributed in the hope that it will be useful, 11 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 12 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 1.1 christos GNU General Public License for more details. 14 1.1 christos 15 1.1 christos You should have received a copy of the GNU General Public License 16 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 1.1 christos 18 1.1 christos #include <string.h> 19 1.1 christos 20 1.1 christos typedef struct point 21 1.1 christos { 22 1.1 christos int x; 23 1.1 christos int y; 24 1.1 christos } point_t; 25 1.1 christos 26 1.1.1.2 christos typedef struct 27 1.1.1.2 christos { 28 1.1.1.2 christos point_t the_point; 29 1.1.1.2 christos } struct_point_t; 30 1.1.1.2 christos 31 1.1 christos typedef union 32 1.1 christos { 33 1.1 christos int an_int; 34 1.1 christos char a_char; 35 1.1 christos } union_t; 36 1.1 christos 37 1.1 christos typedef struct 38 1.1 christos { 39 1.1 christos union_t the_union; 40 1.1 christos } struct_union_t; 41 1.1 christos 42 1.1 christos typedef enum 43 1.1 christos { 44 1.1 christos ENUM_FOO, 45 1.1 christos ENUM_BAR, 46 1.1 christos } enum_t; 47 1.1 christos 48 1.1 christos typedef void (*function_t) (int); 49 1.1 christos 50 1.1 christos static void 51 1.1 christos my_function(int n) 52 1.1 christos { 53 1.1 christos } 54 1.1 christos 55 1.1 christos #ifdef __cplusplus 56 1.1 christos 57 1.1 christos struct Base 58 1.1 christos { 59 1.1 christos Base (int a_) : a (a_) {} 60 1.1 christos 61 1.1 christos virtual int get_number () { return a; } 62 1.1 christos 63 1.1 christos int a; 64 1.1 christos 65 1.1 christos static int a_static_member; 66 1.1 christos }; 67 1.1 christos 68 1.1 christos int Base::a_static_member = 2019; 69 1.1 christos 70 1.1 christos struct Deriv : Base 71 1.1 christos { 72 1.1 christos Deriv (int b_) : Base (42), b (b_) {} 73 1.1 christos 74 1.1 christos virtual int get_number () { return b; } 75 1.1 christos 76 1.1 christos int b; 77 1.1 christos }; 78 1.1 christos 79 1.1 christos #endif 80 1.1 christos 81 1.1 christos int global_symbol = 42; 82 1.1 christos 83 1.1 christos int 84 1.1 christos main () 85 1.1 christos { 86 1.1 christos point_t a_point_t = { 42, 12 }; 87 1.1 christos point_t *a_point_t_pointer = &a_point_t; 88 1.1 christos #ifdef __cplusplus 89 1.1 christos point_t &a_point_t_ref = a_point_t; 90 1.1 christos #endif 91 1.1 christos struct point another_point = { 123, 456 }; 92 1.1.1.2 christos struct_point_t a_struct_with_point = { a_point_t }; 93 1.1 christos 94 1.1 christos struct_union_t a_struct_with_union; 95 1.1 christos /* Fill the union in an endianness-independent way. */ 96 1.1 christos memset (&a_struct_with_union.the_union, 42, 97 1.1 christos sizeof (a_struct_with_union.the_union)); 98 1.1 christos 99 1.1 christos enum_t an_enum = ENUM_BAR; 100 1.1 christos 101 1.1 christos const char *a_string = "hello world"; 102 1.1 christos const char *a_binary_string = "hello\0world"; 103 1.1 christos const char a_binary_string_array[] = "hello\0world"; 104 1.1 christos 105 1.1 christos const int letters_repeat = 10; 106 1.1 christos char a_big_string[26 * letters_repeat + 1]; 107 1.1 christos a_big_string[26 * letters_repeat] = '\0'; 108 1.1 christos for (int i = 0; i < letters_repeat; i++) 109 1.1 christos for (char c = 'A'; c <= 'Z'; c++) 110 1.1 christos a_big_string[i * 26 + c - 'A'] = c; 111 1.1 christos 112 1.1 christos int an_array[] = { 2, 3, 5 }; 113 1.1 christos 114 1.1 christos int an_array_with_repetition[] = { 115 1.1 christos 1, /* 1 time. */ 116 1.1 christos 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 12 times. */ 117 1.1 christos 5, 5, 5, /* 3 times */ 118 1.1 christos }; 119 1.1 christos 120 1.1 christos int *a_symbol_pointer = &global_symbol; 121 1.1 christos 122 1.1 christos #ifdef __cplusplus 123 1.1 christos Deriv a_deriv (123); 124 1.1 christos Base &a_base_ref = a_deriv; 125 1.1 christos #endif 126 1.1 christos 127 1.1 christos return 0; /* break here */ 128 1.1 christos } 129