How to suppress "unused parameter" warnings in C?

nixgadget picture nixgadget · Aug 30, 2010 · Viewed 181.9k times · Source

For instance:

Bool NullFunc(const struct timespec *when, const char *who)
{
   return TRUE;
}

In C++ I was able to put a /*...*/ comment around the parameters. But not in C of course, where it gives me the error error: parameter name omitted.

Answer

Job picture Job · Aug 30, 2010

I usually write a macro like this:

#define UNUSED(x) (void)(x)

You can use this macro for all your unused parameters. (Note that this works on any compiler.)

For example:

void f(int x) {
    UNUSED(x);
    ...
}