Re:Android Project Changeset 4f8b683: libc/memset.c
by humbledrone on Tuesday May 25, 2010 @08:58PM
(#1379197)
It's not hard to type a statement like "(void)v;" to explicitly say, "v is intentionally unused." I fail to see the drawback of this approach. Of course you should only do this when (1) you can't remove the parameter from the function's prototype and (2) there is a good reason for it to be unused. But once you develop that habit, the compiler can help you catch bugs that are otherwise easy to miss. Sounds like a worthwhile tradeoff to me.
Re:Android Project Changeset 4f8b683: libc/memset.c
by leif on Wednesday May 26, 2010 @01:42AM
(#1379614)
What you want is __attribute__((unused)), assuming you're compiling with gcc.
Re:Android Project Changeset 4f8b683: libc/memset.c
by tedunangst on Tuesday May 25, 2010 @10:17PM
(#1379318)
Then you get a "statement with no effect" warning, which is usually more serious. I'll take a bogus warning in real code over a bogus warning in contrived code any day.
Re:Android Project Changeset 4f8b683: libc/memset.c
by cperciva on Tuesday May 25, 2010 @10:50PM
(#1379362)
I've never seen a compiler issue a warning about "(void)foo;". Even compilers which issue 'statement with no effect' warnings normally recognize deliberate casts to void as a way of saying "shut up, I know what I'm doing".
Re:Android Project Changeset 4f8b683: libc/memset.c
by torpor on Wednesday May 26, 2010 @04:11AM
(#1379801)
>There are dozens of perfectly valid reasons why a parameter would go unused, so the occasional error just gets lost in the noise.
Such as?
Re:Android Project Changeset 4f8b683: libc/memset.c
by kelnos on Wednesday May 26, 2010 @05:59AM
(#1379922)
I can only think of a few, but they're valid:
1. An API-defined callback signature where you need to use (for example) the first and third parameters, and not the second.
2. A public API function that has become deprecated and the previous behavior is emulated in a way that doesn't require all the parameters.
3. Stub/wrapper functions.
4. Init/cleanup functions for modules written to a plugin API, when all parameters passed are not needed in all cases.
5. Language binding closure/thunk functions.
Most of the uses, I think, boil down to backwards compat and fixed callback/plugin interfaces. In those cases I think an __attribute__((unused)) or void cast aren't a huge burden. I usually turn on -Wunused-parameter just in case.
It's more helpful in C++, which can omit parameter names to indicate that it's intentionally unused. But then you're using C++; not worth the tradeoff.