gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:45:23 29 4
gpt4 key购买 nike

我在网上看到很多关于 -Wformat=2 的提及Clang 的选项,有时与已知的 -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 卷 -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 有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15171017/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com