This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: unused variable warning


skaller <skaller@users.sourceforge.net> writes:

> In gcc/g++ version 4.0 there is no way to turn off the 
> unused variable warning enabled by -Wall with a command
> line switch.

How about -Wno-unused-variable?

> I think this is a bug: it should be possible to selectively
> turn on or off all warnings (on the command line).

There is work on progress to address that.

> The advice in the documentation is to attach 
> 
> __attribute__((unused))
> 
> to the selected variable. This may be inappropriate for
> three distinct reasons:
> 
> (a) It is a GNU extension
> (b) it clutters the code
> (c) It isn't always easy to tell if a variable is unused

While (a) and (b) are undeniable, (c) is not an issue; the attribute
suppresses the unused warning, but does not cause any trouble if the
variable is in fact used.

To address (a) and (b), the gcc sources themselves do this:

#ifndef ATTRIBUTE_UNUSED
#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
#endif /* ATTRIBUTE_UNUSED */

int fn (int arg ATTRIBUTE_UNUSED)

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]