RE: Turning warning off

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

 



> Michael Young wrote:
> Specifically, I'm looking for a way to turn off a specific 
> warning inline, with the ability to restore it again - 

That exists only in the form of the __attribute__ ((unused)) mechanism.

 You can turn it off for an entire translation unit:

 -Wno-unused

Actually you can get a little more fine-grained than that:

 -Wno-unused-label
 -Wno-unused-variable
 -Wno-unusued-parameter
 -Wno-unused-value

The -Wno-unused does all of them.

These options are not listed in the manual because ...

  Each of these specific warning options also has a negative
  for beginning `-Wno-' to turn off warnings; for example,
  `-Wno-implicit'. This manual lists only one of the two
  forms, whichever is not the default.

> analogous to the #pragma warning directive supported in MS 
> VC++ (see 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-
> us/vclang/html/_predir_warning.asp for details).

GCC stays away from using #pragma, because of its disadvantages. For
instance, because it's a preprocessor directive, a #pragma cannot be
constructed using macros.  Thus to switch among #pragma's based on the
compiler identity, you have to repeat #ifdef everywhere.

  #ifdef _MSVC
  #pragma warning (disable: NNNN)
  #endif
  ...

  #ifdef MSVC
  #pragma warning (enable: NNNN)
  #endif

The use of the __attribute__ ((unused)) extension can be hidden behind
macros.


[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