2 ms·
I much prefer being warned about unused variables and explicitely having to silence those warnings on a case by case basis though - especially when refactoring
by flohofwoe 3y ago
I much prefer being warned about unused variables and explicitely having to silence those warnings on a case by case basis though - especially when refactoring (one option is to use a wrapper macro MAYBE_UNUSED(bla) macro, or GCC's __attribute__((unused)) or the C++ [[unused]], or the C23 [[maybe_unused]].
But of all those options, "(void)bla;" might actually be the least clutter (and at the same time the most compatible).
- mtklein 3y agoI agree that (void)bla is desirably clear, pithy and unambiguous. And I like something like this if I'm dealing with functions with more than a couple unused parameters: static void unused_(int x, ...) { (void)x; } #define unused(...) unused_(0, __VA_ARGS__) This way you can just have one `unused(foo,bar,baz,quux);` line at the top of the function listing all unused parameters.