Do not give the variable a name (C++)
void foo(int /*bar*/) {
...
}
Tell your compiler using a compiler specific nonstandard mechanism
See individual answers for __attribute__((unused))
, various #pragma
s and so on. Optionally, wrap a preprocesor macro around it for portability.
Switch the warning off
IDEs can signal unused variables visually (different color, or underline). Having that, compiler warning may be rather useless.
In GCC and Clang, add -Wno-unused-parameter
option at the end of the command line (after all options that switch unused parameter warning on, like -Wall
, -Wextra
).
Add a cast to void
void foo(int bar) {
(void)bar;
}
as per jamesdlin's answer and http://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/