• <small id='YoG0x'></small><noframes id='YoG0x'>

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

      <tfoot id='YoG0x'></tfoot>

        如何最好地消除有关未使用变量的警告?

        时间:2023-09-19
      1. <i id='cPv59'><tr id='cPv59'><dt id='cPv59'><q id='cPv59'><span id='cPv59'><b id='cPv59'><form id='cPv59'><ins id='cPv59'></ins><ul id='cPv59'></ul><sub id='cPv59'></sub></form><legend id='cPv59'></legend><bdo id='cPv59'><pre id='cPv59'><center id='cPv59'></center></pre></bdo></b><th id='cPv59'></th></span></q></dt></tr></i><div id='cPv59'><tfoot id='cPv59'></tfoot><dl id='cPv59'><fieldset id='cPv59'></fieldset></dl></div>
            <tbody id='cPv59'></tbody>

          <legend id='cPv59'><style id='cPv59'><dir id='cPv59'><q id='cPv59'></q></dir></style></legend>

        • <tfoot id='cPv59'></tfoot>

                  <bdo id='cPv59'></bdo><ul id='cPv59'></ul>
                • <small id='cPv59'></small><noframes id='cPv59'>

                  本文介绍了如何最好地消除有关未使用变量的警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个跨平台应用程序,在我的一些函数中,并非所有传递给函数的值都被利用.因此我收到 GCC 的警告,告诉我有未使用的变量.

                  I have a cross platform application and in a few of my functions not all the values passed to functions are utilised. Hence I get a warning from GCC telling me that there are unused variables.

                  围绕警告编码的最佳方式是什么?

                  What would be the best way of coding around the warning?

                  函数周围的#ifdef?

                  An #ifdef around the function?

                  #ifdef _MSC_VER
                  void ProcessOps::sendToExternalApp(QString sAppName, QString sImagePath, qreal qrLeft, qreal qrTop, qreal qrWidth, qreal qrHeight)
                  #else
                  void ProcessOps::sendToExternalApp(QString sAppName, QString sImagePath, qreal /*qrLeft*/, qreal /*qrTop*/, qreal /*qrWidth*/, qreal /*qrHeight*/)
                  #endif
                  {
                  

                  这太难看了,但似乎是编译器喜欢的方式.

                  This is so ugly but seems like the way the compiler would prefer.

                  或者我是否在函数末尾为变量赋值为零?(我讨厌它,因为它改变了程序流程中的某些内容以消除编译器警告).

                  Or do I assign zero to the variable at the end of the function? (which I hate because it's altering something in the program flow to silence a compiler warning).

                  有正确的方法吗?

                  推荐答案

                  您可以将它放在 "(void)var;" 表达式(什么都不做)中,以便编译器看到它被使用.这在编译器之间是可移植的.

                  You can put it in "(void)var;" expression (does nothing) so that a compiler sees it is used. This is portable between compilers.

                  例如

                  void foo(int param1, int param2)
                  {
                      (void)param2;
                      bar(param1);
                  }
                  

                  或者,

                  #define UNUSED(expr) do { (void)(expr); } while (0)
                  ...
                  
                  void foo(int param1, int param2)
                  {
                      UNUSED(param2);
                      bar(param1);
                  }
                  

                  这篇关于如何最好地消除有关未使用变量的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何列出 .so 文件中的符号 下一篇:为什么这个循环会产生“警告:迭代 3u 调用未定义

                  相关文章

                  最新文章

                  • <bdo id='7iIhZ'></bdo><ul id='7iIhZ'></ul>

                  <legend id='7iIhZ'><style id='7iIhZ'><dir id='7iIhZ'><q id='7iIhZ'></q></dir></style></legend>

                  <small id='7iIhZ'></small><noframes id='7iIhZ'>

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