Last Update 2021/09/05
-Wimplicit-int
型指定の無い宣言に対して警告を出力
テスト概要
-Wimplicit-intオプションを使用したコンパイル時の警告出力例
オプションを使用せずにコンパイルを実行した際の警告出力例
-Wallオプションを使用した場合の警告出力例
実行環境
GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1
GNU C Library 2.28
GNU Binutils 2.31.1
コード例・出力内容中の表記
・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
使用ファイル
sample.c
#include <stdio.h>
/* 型指定の無い関数宣言 */
sampFunc(void);
/* 型指定の無い関数定義 */
sampFunc(void)
{
}
int main(void)
{
/* 型指定の無い変数宣言 */
static i;
i = 0;
printf("%d\n", i);
return 0;
}
-Wimplicit-intオプションを使用したコンパイル時の警告出力例
-Wimplicit-intオプションを指定して実行
$ gcc -Wimplicit-int sample.c
sample.c:4:1: warning: data definition has no type or storage class
sampFunc(void);
^~~~~~~~
sample.c:4:1: warning: type defaults to ‘int’ in declaration of ‘sampFunc’ [-Wimplicit-int]
sample.c:7:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
sampFunc(void)
^~~~~~~~
sample.c: In function ‘main’:
sample.c:14:9: warning: type defaults to ‘int’ in declaration of ‘i’ [-Wimplicit-int]
static i;
^
$ 型や保存クラスの指定が無い事についての警告・デフォルト型に関する情報が出力される
オプションを使用せずにコンパイルを実行した際の警告出力例
オプションを使用せずに実行
$ gcc sample.c
sample.c:4:1: warning: data definition has no type or storage class
sampFunc(void);
^~~~~~~~
sample.c:4:1: warning: type defaults to ‘int’ in declaration of ‘sampFunc’ [-Wimplicit-int]
sample.c:7:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
sampFunc(void)
^~~~~~~~
sample.c: In function ‘main’:
sample.c:14:9: warning: type defaults to ‘int’ in declaration of ‘i’ [-Wimplicit-int]
static i;
^
$ -Wimplicit-intオプションを指定した場合と同じ出力内容
-Wallオプションを使用した場合の警告出力例
-Wallオプションを使用して実行
$ gcc -Wall sample.c
sample.c:4:1: warning: data definition has no type or storage class
sampFunc(void);
^~~~~~~~
sample.c:4:1: warning: type defaults to ‘int’ in declaration of ‘sampFunc’ [-Wimplicit-int]
sample.c:7:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
sampFunc(void)
^~~~~~~~
sample.c: In function ‘main’:
sample.c:14:9: warning: type defaults to ‘int’ in declaration of ‘i’ [-Wimplicit-int]
static i;
^
sample.c: In function ‘sampFunc’:
sample.c:9:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
$ -Wallオプションに-Wimplicit-intが含まれる