Loose-Info.com
Last Update 2021/05/22
TOP - 各種テスト - gcc - 警告関連のオプション - フォーマット文字列関連のオプション - -Wno-format-zero-length

-Wno-format-zero-length
-Wformatが指定されている場合、長さ0のフォーマット文字列に関して警告しない

テスト概要

オプション無し、-Wformatのみ、-Wformatと-Wno-format-zero-lengthをそれぞれ指定した場合の出力を比較

実行環境

GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1


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

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

使用ファイル


sample.c
#include <stdio.h> int main(void) { int n = 1; /* フォーマット文字列と引数の不一致 */ printf("n = %f\n", n); /* 長さが0のフォーマット文字列 */ printf(""); return 0; }

動作テスト

オプション無し、-Wformatのみ、-Wformatと-Wno-format-zero-lengthをそれぞれ指定した場合の出力を比較

オプション無しで実行
$ gcc sample.c $ 一切警告は出力されない

-Wformatのみを指定して実行
$ gcc -Wformat sample.c sample.c: In function ‘main’: sample.c:8:15: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘int’ [-Wformat=] printf("n = %f\n", n); フォーマット文字列と引数の不一致 ~^ ~ %d sample.c:11:9: warning: zero-length gnu_printf format string [-Wformat-zero-length] printf(""); 長さが0のフォーマット文字列 ^~ $

-Wformatと-Wno-format-zero-lengthを指定して実行
$ gcc -Wformat -Wno-format-zero-length sample.c sample.c: In function ‘main’: sample.c:8:15: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘int’ [-Wformat=] printf("n = %f\n", n); ~^ ~ %d $ -Wformat-zero-lengthに関する警告は出力されない