This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: -Wold-style-cast and standard library macros
- From: "John (Eljay) Love-Jensen" <eljay at adobe dot com>
- To: Yang Zhang <yanghatespam at gmail dot com>
- Cc: GCC-help <gcc-help at gcc dot gnu dot org>
- Date: Mon, 23 Feb 2009 12:32:51 -0800
- Subject: Re: -Wold-style-cast and standard library macros
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