This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: unused variable warning
- From: Ian Lance Taylor <ian at airs dot com>
- To: skaller <skaller at users dot sourceforge dot net>
- Cc: gcc at gcc dot gnu dot org
- Date: 29 Aug 2005 01:00:00 -0700
- Subject: Re: unused variable warning
- References: <1125291034.27792.15.camel@localhost.localdomain>
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