What is the best way to suppress A "Unused variable x" warning?

Viewed 91498

What is the best/neatest way to suppress a compiler (in this case GCC) like "Unused variable x" warning?

I don't want to give any certain flags to GCC to remove all these warnings, just for special cases.

11 Answers

The cast to a void is the best approach because it shows that you didn't "accidentally" keep the variable in your code - ie: this function might be an instance where you have a table of function pointers that need the same parameter types and return types, but in this particular table entry you are not using the parameter.

That said, if you don't need it, get rid of it. ;)

Related