Re: How to ignore Wall errors for a portion of code

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

 



Hi Joezac,

I do not believe there is a mechanism in GCC to do quite what you want.

There have been quite a few requests (including from myself) for inline
#pragma control over warnings generation, similar to what MSVC has in their
compiler.

However, there are several reasons why this hasn't happened.

Before I go into that history (as I poorly understand it), you may be able
to employ this mechanism to sort of do what you want:

#pragma GCC system_header

q.v. #pragma GCC system_header
http://gcc.gnu.org/onlinedocs/gcc-4.1.1/cpp/System-Headers.html

q.v. -Wno-system-header
http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Warning-Options.html

- - - - -

Many years ago, the GNU folks were strongly in disfavor of the #pragma
mechanism.  There list of objections to it were lengthy and, in my opinion,
well thought out and compelling.  So they refrained from utilizing the
#pragma mechanism as much as they could, and instead enhanced the C/C++
languages using other techniques such as __attribute__ and other extensions.

The Powers That Be in the standards committees eventually agreed with the
GNU folks, and enhanced the #pragma facilities which addressed or
compromised on all the GNU complaints against the #pragma mechanism.  There
was much rejoicing.  But due to culture or inertial, the GNUrus were not
very interested in going #pragma hog wild.

So that's the glossy overview of the #pragma backstory.

- - - - -

The warning story is a bit different.

In the beginning, there were expensive, powerful compilers that would reject
dicey code.  To make compilers smaller and faster, the C compiler writers
decided to separate that diagnostic functionality out of the compiler and
put it into a different tool, called lint.

Over time, some compiler writers concluded that separating out the
functionality from the compiler was a mistake.

So, many years ago when I was using GCC's g++, and I asked on this forum
"Anyone know of a good lint program for C++ code?"  The answer was along the
lines of "The GNU philosophy is that the lint facilities belong in the
compiler.  That is enable by turning on the compiler warnings."

For me, that was an "AHA!" moment.

Because of the viewpoint about warnings being the holistic lint-like
facilities, the desire to enable or disable them inline in the code becomes
mu ("unask the question").

- - - - -

The last chapter of the story is not going to make you happy.

GCC is a community developed compiler.

The GNUrus who currently put in long hours honing GCC each have their own
agendas, and incorporating the facilities to control warning emission
behavior inline the source code has either been low on their collective
priority list, or for a faction of the GNUrus, is actually considered a
terrible malfeature (a wart).

But if you are really keen on having warning emission control inline in the
code... the beauty of open source is that you can do that.

For Quick-&-Dirty alternative, you can post-process the GCC output with
Perl, Python, sed, awk, or whatever other preferred regex capable scripting
engine you prefer, and filter out the undesired messages.

Sincerely,
--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