Last Update 2021/10/05
-Wno-int-conversion
整数からポインタ、ポインタから整数への互換性の無い変換が生じた場合でも警告しない
テスト概要
オプション無し、および-Wno-int-conversionオプションを使用した際の警告出力例
実行環境
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>
int main(void)
{
int *np;
/* ポインタの整数への代入 */
int n = np;
/* 整数のポインタへの代入 */
np = 30;
return 0;
}
オプション無しでコンパイルを実行
$ gcc sample.c
sample.c: In function ‘main’:
sample.c:8:10: warning: initialization of ‘int’ from ‘int *’ makes integer from pointer without a cast [-Wint-conversion]
int n = np;
^~
sample.c:11:5: warning: assignment to ‘int *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
np = 30;
^
$ キャスト無しの整数・ポインタ変換発生に関する警告
-Wno-int-conversionオプション使用してコンパイルを実行
$ gcc -Wno-int-conversion sample.c エラー・警告無し
$