Unused parameter warning of GCC

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

2 thoughts on “Unused parameter warning of GCC”

  1. I usually make it explicit in the code like this:

    void IntToString(int num, int off) {

    And usually wrapped in a macro: #define UNUSED(expr) (void)expr


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s