Portable UNUSED parameter macro used on function signature for C and C++

The way I do it is like this:

#define UNUSED(x) (void)(x)
void foo(const int i) {
    UNUSED(i);
}

I’ve not had a problem with that in Visual Studio, Intel, gcc and clang.

The other option is to just comment out the parameter:

void foo(const int /*i*/) {
  // When we need to use `i` we can just uncomment it.
}

Leave a Comment