๐ 2014-Sep-10 โฌฉ โ๏ธ Ashwin Nanjappa โฌฉ ๐ท๏ธ gcc, warning โฌฉ ๐ Archive
GCC throws a unused parameter warning if you are compiling your code with one of these options: -Wunused-parameter
, -Wunused
or -Wextra
.
The warning message looks like this:
foo.cpp:43:40: warning: unused parameter โoffโ [-Wunused-parameter]
string IntToString(int num, int off)
^
In most scenarios, this warning is good since you find out that maybe this parameter is not being used currently, so it can be removed from the definition, declaration and the calls.
However, sometimes the function definition cannot be changed. For example, if the function is a callback that is required by a library. In such a case, the function signature cannot be changed even if you are not using that parameter inside your callback.
There is a simple solution for this scenario: remove the parameter name, just keep the parameter type. For example, to fix the function shown above, you could change its definition to:
string IntToString(int num, int)
{
// Code of function here
}
This keeps the function signature, so it still works with the library. But since the parameter name is gone, you no longer get the warning. ๐
Tried with: GCC 4.9 and Ubuntu 14.04