C: warning: too many arguments for format [-Wformat-extra-args]
生活随笔
收集整理的這篇文章主要介紹了
C: warning: too many arguments for format [-Wformat-extra-args]
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
文章目錄
- 警告
- 代碼
- 原因
- 另外一例
- gcc 編譯器相關(guān)的代碼
警告
cc1: warning: -Wformat-extra-args ignored without -Wformat [-Wformat-extra-args]
代碼
gcc -Wformat-extra-args timer.c
printf(“handler set timerout=1\n”, “abc”); 、、、后面這個(gè) “abc”多余,或者 前面的少了%s;
原因
這個(gè)警告的原因是,format里沒(méi)有%s,但是卻傳進(jìn)來(lái)一個(gè) 常量字符串,給format。
另外一例
%z是標(biāo)識(shí)size_t的一個(gè)說(shuō)明符,但是數(shù)據(jù)類型還是要在后面跟著: %zu;
sizeof.c:10:9: warning: too many arguments for format [-Wformat-extra-args]
printf(“sizeof(double)=%z\n”, sizeof(double));
gcc 編譯器相關(guān)的代碼
gcc/c-family/c-format.c
/* If there were extra arguments to the format, normally warn. However,the standard does say extra arguments are ignored, so in the specificcase where we have multiple leaves (conditional expressions orngettext) allow extra arguments if at least one leaf didn't have extraarguments, but was otherwise OK (either non-literal or checked OK).If the format is an empty string, this should be counted similarly to thecase of extra format arguments. */if (res.number_extra_args > 0 && res.number_non_literal == 0&& res.number_other == 0){if (res.extra_arg_loc == UNKNOWN_LOCATION)res.extra_arg_loc = loc;warning_at (res.extra_arg_loc, OPT_Wformat_extra_args,"too many arguments for format");}總結(jié)
以上是生活随笔為你收集整理的C: warning: too many arguments for format [-Wformat-extra-args]的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: hive插入多条数据sql_HIVE s
- 下一篇: 三七女生节,解密阿里女程序员们的代码诗!