Re: -Wold-style-cast and standard library macros

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Yang Zhang,

> But is there any workaround for this problem in general, where the source of
the problem is a macro defined in a system header?  I'm seeing the same problem
with FD_SET, FD_ISSET, etc.

Well... I did provide a general workaround.

If you have a macro which violates a -Wsomething, then you will need to
intercept the macro, #undef it, and correct it.  One correction for C++ code
is to replace the macro with a constant (for a macro constant), or an inline
function (for a macro function), or a template function, or perhaps a
template class.

Sometimes there are macros which are just too hard to replace with a C++
construct.  For those, you will need to intercept the macro, #undef it, and
rewrite the macro such that it does not incur the warning you are trying to
avoid.

Keep in mind that for most operating systems, the headers are C headers, not
C++ headers.  They abide by C-isms.  If they are C++ friendly, they may put
in some #ifdef __cplusplus / extern "C" { / #endif prologue, and the closing
epilogue blocks.  But they probably are not concerned with avoiding C++
warnings for proper C code that is C compliant.  Especially if it is code
that is not doing anything particularly heinous.

Another solution presented by someone on this forum many years ago is to use
a tool like Perl (Python, Ruby, or even sed) to filter the output from the
warnings deemed benign which you don't want to see.  Perhaps this approach
is a more suitable general workaround.

HTH,
--Eljay



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux