1. <i id='BAiiz'><tr id='BAiiz'><dt id='BAiiz'><q id='BAiiz'><span id='BAiiz'><b id='BAiiz'><form id='BAiiz'><ins id='BAiiz'></ins><ul id='BAiiz'></ul><sub id='BAiiz'></sub></form><legend id='BAiiz'></legend><bdo id='BAiiz'><pre id='BAiiz'><center id='BAiiz'></center></pre></bdo></b><th id='BAiiz'></th></span></q></dt></tr></i><div id='BAiiz'><tfoot id='BAiiz'></tfoot><dl id='BAiiz'><fieldset id='BAiiz'></fieldset></dl></div>
  2. <tfoot id='BAiiz'></tfoot>

  3. <legend id='BAiiz'><style id='BAiiz'><dir id='BAiiz'><q id='BAiiz'></q></dir></style></legend>

        <bdo id='BAiiz'></bdo><ul id='BAiiz'></ul>

      <small id='BAiiz'></small><noframes id='BAiiz'>

      __attribute__((format(printf, 1, 2))) 用于 MSVC?

      时间:2023-10-06

        • <bdo id='fvGH2'></bdo><ul id='fvGH2'></ul>

                  <tbody id='fvGH2'></tbody>
                <tfoot id='fvGH2'></tfoot>
              • <i id='fvGH2'><tr id='fvGH2'><dt id='fvGH2'><q id='fvGH2'><span id='fvGH2'><b id='fvGH2'><form id='fvGH2'><ins id='fvGH2'></ins><ul id='fvGH2'></ul><sub id='fvGH2'></sub></form><legend id='fvGH2'></legend><bdo id='fvGH2'><pre id='fvGH2'><center id='fvGH2'></center></pre></bdo></b><th id='fvGH2'></th></span></q></dt></tr></i><div id='fvGH2'><tfoot id='fvGH2'></tfoot><dl id='fvGH2'><fieldset id='fvGH2'></fieldset></dl></div>

                <small id='fvGH2'></small><noframes id='fvGH2'>

                <legend id='fvGH2'><style id='fvGH2'><dir id='fvGH2'><q id='fvGH2'></q></dir></style></legend>
                本文介绍了__attribute__((format(printf, 1, 2))) 用于 MSVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                使用 GCC,我可以指定 __attribute__((format(printf, 1, 2))) ,告诉编译器这个函数采用 vararg 参数,这些参数是 printf 格式说明符.

                With GCC, I can specify __attribute__((format(printf, 1, 2))) , telling the compiler that this function takes vararg parameters that are printf format specifiers.

                这在我包装的情况下非常有用,例如vsprintf 函数族.我可以有extern void log_error(const char *format, ...) __attribute__((format(printf, 1, 2)));

                This is very helpful in the cases where I wrap e.g. the vsprintf function family. I can have extern void log_error(const char *format, ...) __attribute__((format(printf, 1, 2)));

                每当我调用这个函数时,gcc 都会检查参数的类型和数量是否符合给定的格式说明符,就像 printf 一样,如果不是,则发出警告.

                And whenever I call this function, gcc will check that the types and number of arguments conform to the given format specifiers as it would for printf, and issue a warning if not.

                微软的 C/C++ 编译器有没有类似的东西?

                Does the Microsoft C/C++ compiler have anything similar ?

                推荐答案

                虽然 GCC 在启用 -Wformat 时检查格式说明符,但 VC++ 没有这种检查,即使对于标准函数也是如此,因此没有与此等效的 __attribute__ 因为没有等效于 -Wformat.

                While GCC checks format specifiers when -Wformat is enabled, VC++ has no such checking, even for standard functions so there is no equivalent to this __attribute__ because there is no equivalent to -Wformat.

                我认为微软对 C++ 的重视(通过保持 C++ 的 ISO 合规性来证明,同时只支持 C89)可能是 VC++ 没有格式说明符检查的部分原因;在 C++ 中使用 格式说明符是不必要的.

                I think Microsoft's emphasis on C++ (evidenced by maintaining ISO compliance for C++ while only supporting C89) may be in part the reason why VC++ does not have format specifier checking; in C++ using <iostream> format specifiers are unnecessary.

                这篇关于__attribute__((format(printf, 1, 2))) 用于 MSVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:C++:“float"的 printf() 格式规范是什么? 下一篇:如何找到当前目录?

                相关文章

                最新文章

                  <bdo id='0kNEu'></bdo><ul id='0kNEu'></ul>

                1. <i id='0kNEu'><tr id='0kNEu'><dt id='0kNEu'><q id='0kNEu'><span id='0kNEu'><b id='0kNEu'><form id='0kNEu'><ins id='0kNEu'></ins><ul id='0kNEu'></ul><sub id='0kNEu'></sub></form><legend id='0kNEu'></legend><bdo id='0kNEu'><pre id='0kNEu'><center id='0kNEu'></center></pre></bdo></b><th id='0kNEu'></th></span></q></dt></tr></i><div id='0kNEu'><tfoot id='0kNEu'></tfoot><dl id='0kNEu'><fieldset id='0kNEu'></fieldset></dl></div>

                    <small id='0kNEu'></small><noframes id='0kNEu'>

                    <legend id='0kNEu'><style id='0kNEu'><dir id='0kNEu'><q id='0kNEu'></q></dir></style></legend>
                    <tfoot id='0kNEu'></tfoot>