Last Update 2021/03/29
-w
全ての警告メッセージを出力しない
テスト概要
-w オプション有りと無しの場合を比較
実行環境
GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1
GNU C Library 2.28
GNU Binutils 2.31.1
コード例・出力内容中の表記
・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
使用ファイル
main.c
/* -w オプション動作確認用ソースファイル */
#include <stdio.h>
int main(void)
{
int n;
int n;
printtf("-w オプション動作確認用ソースファイル\n");
int n;
printttf("-w オプション動作確認用ソースファイル\n");
int n;
printtttf("-w オプション動作確認用ソースファイル\n");
return 0;
}
動作テスト
-w オプション無しでコンパイル
$ gcc main.c
main.c: In function ‘main’:
main.c:9:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ
^
main.c:7:6: note: previous declaration of ‘n’ was here
int n; note
^
main.c:11:2: warning: implicit declaration of function ‘printtf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
printtf("-w オプション動作確認用ソースファイル\n"); 警告
^~~~~~~
printf
main.c:13:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ
^
main.c:9:6: note: previous declaration of ‘n’ was here
int n; note
^
main.c:15:2: warning: implicit declaration of function ‘printttf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
printttf("-w オプション動作確認用ソースファイル\n"); 警告
^~~~~~~~
printf
main.c:17:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ
^
main.c:13:6: note: previous declaration of ‘n’ was here
int n; note
^
main.c:19:2: warning: implicit declaration of function ‘printtttf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
printtttf("-w オプション動作確認用ソースファイル\n"); 警告
^~~~~~~~~
printf
$ 警告を含む全てのメッセージを出力
-w オプション有りでコンパイル
$ gcc -w main.c
main.c: In function ‘main’:
main.c:9:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ
^
main.c:7:6: note: previous declaration of ‘n’ was here
int n; note
^
main.c:13:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ
^
main.c:9:6: note: previous declaration of ‘n’ was here
int n; note
^
main.c:17:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ
^
main.c:13:6: note: previous declaration of ‘n’ was here
int n; note
^
$ 警告以外のメッセージを出力