unused variable warning
Ian Lance Taylor
ian@airs.com
Mon Aug 29 12:14:00 GMT 2005
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
More information about the Gcc
mailing list