教科書のコードをコンパイルするとwarningがでます。これを消したいのですがどうしたら消えますか。
英語が苦手なのでよろしくお願いいたします。
warningの意味もできたらお願いいたします。
コード // スタックの実現例 #include <stdio.h> #include <stdlib.h> //--- スタックを実現する構造体 --- typedef struct { int max; // スタックのサイズ int ptr; // スタックポインタ int *stk; // スタック(の先頭へのポインタ) } Stack; //--- スタックを確保・初期化する --- int StackAlloc(Stack *s, int max) { s->ptr = 0; if ((s->stk = calloc(max, sizeof(int))) == NULL) { // 配列の確保に失敗 s->max = 0; return (-1); } s->max = max; return (0); } //--- スタックを解放する --- void StackFree(Stack *s) { if (s->stk != NULL) { // スタックが正しく生成されていれば free(s->stk); s->max = s->ptr = 0; } } //--- スタックにデータをプッシュ --- int StackPush(Stack *s, int x) { if (s->ptr >= s->max) // スタックが満杯 return (-1); s->stk[s->ptr++] = x; return (0); } //--- スタックからデータをポップ --- int StackPop(Stack *s, int *x) { if (s->ptr <= 0) // スタックが空 return (-1); *x = s->stk[--s->ptr]; return (0); } //--- スタックからデータをピーク --- int StackPeek(const Stack *s, int *x) { if (s->ptr <= 0) // スタックが空 return (-1); *x = s->stk[s->ptr]; return (0); } //--- スタックの大きさを返却 --- int StackSize(const Stack *s) { return (s->max); } //--- スタックに積まれているデータ数を返却 --- int StackNo(const Stack *s) { return (s->ptr); } //--- スタックは空か --- int StackIsEmpty(const Stack *s) { return (s->ptr <= 0); } //--- スタックは満杯か --- int StackIsFull(const Stack *s) { return (s->ptr >= s->max); } //--- スタックを空にする --- void StackClear(Stack *s) { s->ptr = 0; } int main(void) { Stack stk; if (StackAlloc(&stk, 100) == -1) { puts("スタックの確保に失敗しました。"); return (1); } while (1) { int m, x; printf("現在のデータ数:%d/%d\n", StackNo(&stk), StackSize(&stk)); printf("(1) プッシュ (2) ポップ (0) 終了:"); scanf("%d", &m); if (m == 0) break; switch (m) { case 1: printf("データ:"); scanf("%d", &x); if (StackPush(&stk, x) == -1) puts("プッシュできません。"); break; case 2: if (StackPop(&stk, &x) == -1) puts("ポップできません。"); else printf("ポップしたデータは%dです。\n", x); break; } } StackFree(&stk); return (0); } 実行結果 naka@naka ~/meikaicjs/chap10 $ gcc -o list10_1 list10_1.c -Wall list10_1.c: In function 'main': list10_1.c:110:6: warning: this 'if' clause does not guard... [-Wmisleading-indentation] if (StackPush(&stk, x) == -1) ^~ list10_1.c:111:37: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if' puts("プッシュできません。"); break; ^~~~~ list10_1.c:114:6: warning: this 'else' clause does not guard... [-Wmisleading-indentation] else ^~~~ list10_1.c:115:49: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'else' printf("ポップしたデータは%dです。\n", x); break; ^~~~~
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/03/17 09:13