Loose-Info.com
Last Update 2021/10/08
TOP - 各種テスト - gcc - 警告関連のオプション - -Wlarger-than=

-Wlarger-than=オプション引数
オプション引数で指定されたバイト以上のオブジェクトが定義される毎に警告を出力

テスト概要

オプション無し、および-Wlarger-than=オプションを使用した際の警告出力例

実行環境

GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1


コード例・出力内容中の表記

・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。

使用ファイル


sample.c
#include <stdio.h> int main(void) { char a[100] = "a"; char b[101] = "b"; char c[102] = "c"; printf("[%s] [%s] [%s]\n", a, b, c); return 0; }

動作テスト

オプション無しでコンパイルを実行
$ gcc sample.c エラー・警告無し $

-Wlarger-than=オプションに100バイトを指定してコンパイルを実行
$ gcc -Wlarger-than=100 sample.c sample.c: In function ‘main’: sample.c:6:7: warning: size of ‘b’ is 101 bytes [-Wlarger-than=] char b[101] = "b"; ^ sample.c:7:7: warning: size of ‘c’ is 102 bytes [-Wlarger-than=] char c[102] = "c"; ^ $ 指定した100バイトを超えたサイズのオブジェクトに対する警告