加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 17:39:53 所属栏目:百科 来源:网络整理
导读:我在网上看到了很多关于Clang的-Wformat = 2选项的提及,有时与已知的-Wformat( Xcode列为“Typecheck调用printf / scanf的那个”一起提到,尽管它涵盖了更多的字符串格式API现在). 这有什么用呢? 如果确实如此,那么它与-Wformat有什么不同呢? 两者兼有,或者
我在网上看到了很多关于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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读