C: warning: too many arguments for format [-Wformat-extra-args]
生活随笔
收集整理的這篇文章主要介紹了
C: warning: too many arguments for format [-Wformat-extra-args]
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 警告
- 代碼
- 原因
- 另外一例
- gcc 編譯器相關的代碼
警告
cc1: warning: -Wformat-extra-args ignored without -Wformat [-Wformat-extra-args]
代碼
gcc -Wformat-extra-args timer.c
printf(“handler set timerout=1\n”, “abc”); 、、、后面這個 “abc”多余,或者 前面的少了%s;
原因
這個警告的原因是,format里沒有%s,但是卻傳進來一個 常量字符串,給format。
另外一例
%z是標識size_t的一個說明符,但是數據類型還是要在后面跟著: %zu;
sizeof.c:10:9: warning: too many arguments for format [-Wformat-extra-args]
printf(“sizeof(double)=%z\n”, sizeof(double));
gcc 編譯器相關的代碼
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");}總結
以上是生活随笔為你收集整理的C: warning: too many arguments for format [-Wformat-extra-args]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hive插入多条数据sql_HIVE s
- 下一篇: 三七女生节,解密阿里女程序员们的代码诗!