xcode – -Wformat = 2有什么作用?

xcode – -Wformat = 2有什么作用?,第1张

概述我在网上看到了很多关于Clang的-Wformat = 2选项的提及,有时与已知的-Wformat( Xcode列为“Typecheck调用printf / scanf的那个”一起提到,尽管它涵盖了更多的字符串格式API现在). >这有什么用呢? >如果确实如此,那么它与-Wformat有什么不同呢? >两者兼有,或者是另一个的超集是否有用? If it does, what, if anythi 我在网上看到了很多关于Clang的-Wformat = 2选项的提及,有时与已知的-Wformat( Xcode列为“Typecheck调用printf / scanf的那个”一起提到,尽管它涵盖了更多的字符串格式API现在).

>这有什么用呢?
>如果确实如此,那么它与-Wformat有什么不同呢?
>两者兼有,或者是另一个的超集是否有用?

解决方法

If it does,what,if anything,does it do differently from -Wformat?

它是从GCC借来的,因为它被设计成适合的替代品. GCC’s description:

-Wformat=2

Enable -Wformat plus format checks not included in -Wformat. Currently
equivalent to `-Wformat -Wformat-nonliteral -Wformat-security
-Wformat-y2k’.

这回答了你的大部分问题.

Does this do anything at all?

是.以下程序会发出不同的警告,具体取决于-Wformat = 2的存在(或不存在):

__attribute__((__format__ (__printf__,1,2)))static voID F(const char* const pString,...) {}int main(int argc,const char* argv[]) {    F("",0);    F(argv[0],0);    const char str[] = "aaa";    F(str,0);    F("%i",0);    F("%i");    return 0;}

注意:看起来Clang roll -Wformat-security为-Wformat.

最后,我没有测试-Wformat-y2k,但它被GCC定义为:

-Wformat-y2k

If -Wformat is specifIEd,also warn about strftime formats which may yIEld only a two-digit year.

总结

以上是内存溢出为你收集整理的xcode – -Wformat = 2有什么作用?全部内容,希望文章能够帮你解决xcode – -Wformat = 2有什么作用?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1013200.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存