Last Update 2021/04/18
-pedantic-errors
ISOにより定められた言語標準に関する警告をエラーとして出力
テスト概要
-Wpedanticオプションと-pedantic-errorsオプションの出力を比較
実行環境
GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1
GNU C Library 2.28
GNU Binutils 2.31.1
コード例・出力内容中の表記
・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
使用ファイル
sample1.c
sample1.c
#include <stdio.h>
int sampFunc(int n)
{
int a[n]; /* 可変長配列 */
long long int i; /* long long int */
int j;
int *pn = (int []){4, 5, 6}; /* 複合リテラル */
for (i=0; i<n; i++)
{
a[i] = i * i;
}
for (i=0; i<n; i++)
{
for (j=0; j<3; j++)
{
printf("a[%d] = %d : b[%d] = %d\n", i, a[i], j, *(pn + j)) ;
}
}
return n;
}
int main(void)
{
int n = sampFunc(3);
printf("n = %d\n", n);
return 0;
}
-Wpedanticオプションと-std=c90を指定して実行
着色部(青)は-Wpedanticオプションによる出力
着色部(青)は-Wpedanticオプションによる出力
$ gcc -std=c90 -Wpedantic sample1.c
sample1.c: In function ‘sampFunc’:
sample1.c:5:2: warning: ISO C90 forbids variable length array ‘a’ [-Wvla]
int a[n]; /* 可変長配列 */
^~~
sample1.c:6:7: warning: ISO C90 does not support ‘long long’ [-Wlong-long]
long long int i; /* long long int */
^~~~
sample1.c:9:20: warning: ISO C90 forbids compound literals [-Wpedantic]
int *pn = (int []){4, 5, 6}; /* 複合リテラル */
^
$
-pedantic-errorsオプションと-std=c90を指定して実行
着色部(青)は-pedantic-errorsオプションによる出力
着色部(青)は-pedantic-errorsオプションによる出力
$ gcc -std=c90 -pedantic-errors sample1.c
sample1.c: In function ‘sampFunc’:
sample1.c:5:2: error: ISO C90 forbids variable length array ‘a’ [-Wvla]
int a[n]; /* 可変長配列 */
^~~
sample1.c:6:7: error: ISO C90 does not support ‘long long’ [-Wlong-long]
long long int i; /* long long int */
^~~~
sample1.c:9:20: error: ISO C90 forbids compound literals [-Wpedantic]
int *pn = (int []){4, 5, 6}; /* 複合リテラル */
^
$ -pedanticで発生する警告を、エラーとして出力