清理C / C ++代碼會發現可變參數宏的問題

[英]Cleaning up C/C++ code reveals problems with variadic macros


We're doing some code cleanup, fixing signed/unsigned comparisons, running static analysis, etc, on the code base of C, C++, and Java.

我們正在C,C ++和Java的代碼庫上進行一些代碼清理,修復有符號/無符號比較,運行靜態分析等。

One of the warnings we're getting is

我們得到的警告之一是

warning: ISO C does not permit named variadic macros

And its companion warning

和它的同伴警告

warning: ISO C99 requires rest arguments to be used

Now, in the C code I used the C99 standard variadic macro to fix the problem, but in the C++ code, what is the correct answer? Using the same C99 style results in a different warning

現在,在C代碼中我使用C99標准可變參數宏來解決問題,但在C ++代碼中,正確的答案是什么?使用相同的C99樣式會產生不同的警告

warning: anonymous variadic macros were introduced in C99 

For which I don't see any answers.

我沒有看到任何答案。

We're using GCC (G++) 4.4.3 in Linux.

我們在Linux中使用GCC(G ++)4.4.3。

I'm hoping there is some flag, or other method that can correct, or disable it for the specific section of code - but its for the logging which is used in almost every file...

我希望有一些標志或其他方法可以糾正或禁用它的特定代碼部分 - 但它用於幾乎每個文件中使用的日志...

1 个解决方案

#1


13  

Use the gcc option -Wno-variadic-macros to disable that particular warning.

使用gcc選項-Wno-variadic-macros禁用該特定警告。

Edit: (from comments)

編輯:(來自評論)

To disable the warning for a section of code but leave it on in general, use #pragma GCC diagnostic described here.

要禁用某段代碼的警告但通常將其保留,請使用此處所述的#pragma GCC診斷。

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wno-variadic-macros"

    // Your code and/or include files
    // (No variadic warnings here)

#pragma GCC diagnostic pop

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/03/19/72ff18f246d7d63afd574b3a76923e96.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com