cc -Wall -W ファイル名
でコンパイルした際、宣言して使っているにも関わらずコンパイル時に「使用されない変数」と出てきてしまいます。原因として考えられるのはどんなことですか?-Dオプションを使っているのですが、関係はあるのでしょうか?
該当のソースコード
c
1#include <stdio.h> 2#include <stdlib.h> 3 4#ifdef hairetsu_riyou 5 6void bubble_sort_array(int a[], int n); 7void selection_sort_array(int a[], int n); 8void insertion_sort_array(int a[], int n); 9void shell_sort_array(int a[], int n); 10 11#else 12typedef struct { 13 int key; 14 int data; 15}kozotai; 16 17void bubble_sort_kozotai(kozotai a[] , int n); 18void selection_sort_kozotai(kozotai a[] , int n); 19void insertion_sort_kozotai(kozotai a[] , int n); 20void shell_sort_kozotai(kozotai a[], int n); 21 22#endif 23 24int main(void){ 25 int i, tmp; 26 27 int n=100; 28 29#ifdef hairetsu_riyou 30 int hairetsu[100]={412, 54, 595, 329, 24, 488, 313, 272, 129, 210, 31 670, 516, 342, 541, 491, 640, 167, 117, 726, 206, 32 474, 762, 153, 292, 1000, 607, 151, 661, 93, 270, 33 737, 531, 641, 548, 299, 287, 547, 394, 550, 474, 34 443, 261, 707, 503, 403, 739, 226, 646, 778, 588, 35 427, 169, 477, 572, 412, 299, 88, 321, 54, 778, 36 541, 680, 210, 272, 288, 276, 405, 307, 424, 668, 37 756, 255, 190, 449, 35, 435, 91, 486, 58, 408, 38 4, 63, 534, 329, 701, 65, 256, 311, 586, 403, 39 459, 254, 291, 333, 42, 343, 418, 512, 164, 56}; 40 41 for(i=0;i<n;i++){ 42 printf("hairetsu[%d]= %d\n" , i, hairetsu[i]); 43 } 44 45#ifdef BUB 46 bubble_sort_array(hairetsu ,n); 47#endif 48#ifdef SEL 49 selection_sort_array(hairetsu, n); 50#endif 51#ifdef INS 52 insertion_sort_array(hairetsu, n); 53#endif 54#ifdef SHL 55 shell_sort_array(hairetsu, n); 56#endif 57 58 printf("\n\nソート後\n\n"); 59 for(i=0;i<n;i++){ 60 printf("hairetsu[%d]= %d\n" , i, hairetsu[i]); 61 } 62 63 tmp = hairetsu[9]; hairetsu[9] = hairetsu[89]; hairetsu[89] = tmp; 64 tmp = hairetsu[49]; hairetsu[49] = hairetsu[59]; hairetsu[59] = tmp; 65 printf("\n\nほぼソート済\n\n"); 66 for(i=0;i<n;i++){ 67 printf("hairetsu[%d]= %d\n" , i, hairetsu[i]); 68 } 69#ifdef BUB 70 bubble_sort_array(hairetsu ,n); 71#endif 72#ifdef SEL 73 selection_sort_array(hairetsu, n); 74#endif 75#ifdef INS 76 insertion_sort_array(hairetsu, n); 77#endif 78#ifdef SHL 79 shell_sort_array(hairetsu, n); 80#endif 81 82 printf("\n\nソート後\n\n"); 83 for(i=0;i<n;i++){ 84 printf("hairetsu[%d]= %d\n" , i, hairetsu[i]); 85 } 86 87 88 89#else 90 kozotai table[100]; 91 92 for(i=0;i<n;i++){ 93 table[i].key=i; 94 table[i].data=rand()%893; 95 } 96 97 for(i=0;i<n;i++){ 98 printf("table[%d].key= %d table[%d].data= %d\n" , i, table[i].key, i, table[i].data); 99 } 100 101#ifdef BUB 102 bubble_sort_kozotai(table, n); 103#endif 104#ifdef SEL 105 selection_sort_kozotai(table, n); 106#endif 107#ifdef INS 108 insertion_sort_kozotai(table, n); 109#endif 110#ifdef SHE 111 shell_sort_kozotai(table, n); 112#endif 113 114 printf("\n\nソート後\n\n"); 115 116 for(i=0;i<n;i++){ 117 printf("table[%d].key= %d table[%d].data= %d\n" , i, table[i].key, i, table[i].data); 118 } 119#endif 120 121 return 0; 122 123} 124 125 126#if hairetsu_riyou 127 128void bubble_sort_array(int a[], int n); 129 int i, j, t; 130 for (i = 0; i < n-1; i++) { 131 j = n; 132 while (j > i) { 133 if (a[j-1] > a[j]) { 134 t = a[j]; 135 a[j] = a[j-1]; 136 a[j-1] = t; 137 } 138 j--; 139 } 140 } 141} 142 143 144void selection_sort_array(int a[], int n){ 145 int i, j, t, lowest, lowkey; 146 for (i = 0; i < n-1; i++) { 147 lowest = i; 148 lowkey = a[i]; 149 for (j = i+1; j < n; j++) { 150 if (lowkey > a[j]) { 151 lowest = j; 152 lowkey = a[j]; 153 } 154 t = a[lowest]; 155 a[lowest] = a[i]; 156 a[i] = t; 157 } 158} 159 160 161void insertion_sort_array(int a[], int n){ 162 int i, j, t; 163 164 for(i=1; i<n; i++ ){ 165 j=i; 166 while(j>=1 && a[j-1] >a[j]){ 167 t = a[j]; 168 a[j]=a[j-1]; 169 a[j-1]=t; 170 j--; 171 } 172 } 173} 174 175void shell_sort_array(int a[], int n){ 176 int i, j, k, t, w, hikaku=0, koukan=0; 177 178 t = n / 2; 179 while (t > 0) { 180 for (i = 1; i <= t; i++) { 181 for (j = i + t; i <= n; j = j + t) { 182 w = a[j]; 183 k = j - t; 184 while (k > 0) { 185 if (a[k] <= w) {break;} 186 a[k+t] = a[k]; 187 k = k - t; 188 } 189 a[k+t] = w; 190 } 191 } 192 t = t / 2; 193 } 194} 195 196#else 197void bubble_sort_kozotai(kozotai a[], int n){ 198 199 int i, j; 200 kozotai t; 201 202 for (i = 0; i < n-1; i++) { 203 j = n; 204 while (j > i) { 205 if (a[j-1].data > a[j].data) { 206 t = a[j]; 207 a[j] = a[j-1]; 208 a[j-1] = t; 209 } 210 j--; 211 } 212 } 213} 214 215void selection_sort_kozotai(kozotai a[], int n){ 216 217 int i, j, lowest, lowkey; 218 kozotai t; 219 220 for (i = 0; i < n-1; i++) { 221 lowest = i; 222 lowkey = a[i].data; 223 for (j = i+1; j < n; j++) { 224 if (a[lowest].data > a[j].data) { 225 lowest = j; 226 lowkey = a[j].data; 227 } 228 } 229 t = a[lowest]; 230 a[lowest] = a[i]; 231 a[i] = t; 232 } 233} 234 235void insertion_sort_kozotai(kozotai a[], int n){ 236 237 int i, j; 238 kozotai t; 239 240 for(i=1; i<n; i++ ){ 241 j=i; 242 while(j>=1 && a[j-1].data >a[j].data){ 243 t = a[j]; 244 a[j]=a[j-1]; 245 a[j-1]=t; 246 j--; 247 } 248 } 249} 250 251void shell_sort_kozotai(kozotai a[], int n){ 252 253 int i, j, k, t; 254 kozotai w; 255 256 t = n / 2; 257 while (t > 0) { 258 for (i = 1; i <= t; i++) { 259 for (j = i + t; i <= n; j = j + t) { 260 w = a[j]; 261 k = j - t; 262 while (k > 0) { 263 if (a[k].data <= w.data) {break;} 264 a[k+t] = a[k]; 265 k = k - t; 266 } 267 a[k+t] = w; 268 } 269 } 270 t = t / 2; 271 } 272} 273 274#endif
実際のソースコードを「```C」と「```」の間に貼り付けてください。
回答2件
あなたの回答
tips
プレビュー